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 reports deprecation warning about not using ObjectFactory.mapProperty() in Gradle 5.6 #10341

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

Comments

@steffenyount
Copy link

steffenyount commented Aug 22, 2019

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 with ~/tstProj/build.gradle:

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 javax.inject.Inject

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

class MyTask extends DefaultTask {
    final WorkerExecutor workerExecutor

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

    @TaskAction
    def run() {
        Properties myProps = new Properties()
        myProps.setProperty('key1', 'value1')
        myProps.setProperty('key2', 'value2')
        myProps.setProperty('key3', 'value3')

        final WorkQueue workQueue = workerExecutor.processIsolation();

        workQueue.submit(MyRunner.class, { MyParameters params ->
            params.myProps = myProps
        })
    }

    static interface MyParameters extends WorkParameters {
        Property<Properties> getMyProps();
    }

    static abstract class MyRunner implements WorkAction<MyParameters> {
        @Override
        public void execute() {
            Properties myProps = parameters.myProps.get()
            myProps.store(System.out, null)
        }
    }
}

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.
	at MyTask$_run_closure1.doCall(/Users/steffenyount/dev/2/tstProj/build.gradle:33)
	(Run with --stacktrace to get the full stack trace of this deprecation warning.)
#Wed Aug 21 15:17:48 PDT 2019
key3=value3
key2=value2
key1=value1
:myTask (Thread[Execution worker for ':',5,main]) completed. Took 1.49 secs.

BUILD SUCCESSFUL in 2s
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.Properties object to my worker

Steps to Reproduce

See example above.

Your Environment

OSX

@steffenyount steffenyount changed the title New Worker API reports deprecation warning about not using ObjectFactory.mapProperty() New Worker API reports deprecation warning about not using ObjectFactory.mapProperty() in Gradle 5.6 Aug 22, 2019
@ghale
Copy link
Member

ghale commented Aug 22, 2019

Thanks for the report @steffenyount. We're working on a fix for #10323 to go into 5.6.1, but it's good that you've adopted the new worker api semantics. You can get rid of the deprecation by using MapProperty instead of Property<Properties> although that requires you to treat it like a Map in your work action - not sure if that would be an issue for you or not. The issue here (and with #10323) is that there is special handling for Map objects and since Properties is-a Map, it gets caught up in that. We're looking at better ways to handle this.

@ghale
Copy link
Member

ghale commented Aug 23, 2019

See this comment for a little further information on this.

@ghale ghale closed this as completed Aug 23, 2019
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

2 participants