Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Worker API (Java) reports deprecation warning about not using ObjectFactory.mapProperty() in Gradle 5.6 #10343

Closed
steffenyount opened this issue Aug 22, 2019 · 2 comments
Labels

Comments

@steffenyount
Copy link

I'm seeing a deprecation warning about not using ObjectFactory.mapProperty() which I don't think I have any control over.

E.g. a simple project defined across two files

~/tstProj/buildSrc/src/main/java/MyTask.java:

import org.gradle.api.provider.Property;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.workers.IsolationMode;
import org.gradle.workers.WorkAction;
import org.gradle.workers.WorkParameters;
import org.gradle.workers.WorkQueue;
import org.gradle.workers.WorkerExecutor;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;

public class MyTask extends DefaultTask {
    final WorkerExecutor workerExecutor;

    @Inject
    public MyTask(WorkerExecutor workerExecutor) {
        this.workerExecutor = workerExecutor;
    }

    @TaskAction
    public void run() {
        Map<Object, Object> myProps = new LinkedHashMap<>();
        myProps.put("key1", "value1");
        myProps.put("key2", "value2");
        myProps.put("key3", "value3");

        final WorkQueue workQueue = workerExecutor.processIsolation();

        workQueue.submit(MyRunner.class, (MyParameters params) -> {
            params.getMyProps().set(myProps);
        });
    }

    interface MyParameters extends WorkParameters {
        Property<Map<Object, Object>> getMyProps();
    }

   public static abstract class MyRunner implements WorkAction<MyParameters> {
        @Override
        public void execute() {
            final MyParameters params = getParameters();

            final Properties myProps = new Properties();
            myProps.putAll(params.getMyProps().get());


            try {
                myProps.store(System.out, null);
            } catch (IOException e) {
                // do nothing
            }
        }
    }
}

~/tstProj/build.gradle:

import MyTask

task myTask(type: MyTask) {
    description 'My Task'
}

result:

./gradlew myTask
...
> Task :myTask
Caching disabled for task ':myTask' because:
  Build cache is disabled
Task ':myTask' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Using method ObjectFactory.property() method to create a property of type Map<K, V> has been deprecated. This will fail with an error in Gradle 6.0. Please use the ObjectFactory.mapProperty() method instead.
#Thu Aug 22 10:19:16 PDT 2019
key3=value3
key2=value2
key1=value1
:myTask (Thread[Execution worker for ':',5,main]) completed. Took 0.007 secs.

BUILD SUCCESSFUL in 581ms
1 actionable task: 1 executed

Expected Behavior

should not see a deprecation warning about not using ObjectFactory.mapProperty()

Current Behavior

I am seeing a deprecation warning about not using ObjectFactory.mapProperty()

Context

I want to pass a java.util.Map object to my worker

Steps to Reproduce

See example above.

Your Environment

OSX

@steffenyount
Copy link
Author

Note issue is similar to the one reported in #10341

@steffenyount
Copy link
Author

steffenyount commented Aug 22, 2019

Based on @ghale 's comment #10341 (comment)

I tried replacing the Property<Map<Object, Object>> return type with a MapProperty<Object, Object> return type.

That was successful and avoided the deprecation warning about not using ObjectFactory.mapProperty().

So it turns out that I do actually have control over the affected parts and I can make the changes necessary to avoid the warning.

I'll go ahead and resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant