I need dynamic properties. Some properties are set during task creation and other are dynamically calculated based on them. Additionally I want to be able to replace calculation logic with overriding task closure prop.
From my perspective the logic should be encapsulated in the custom task and should be hidden from the user of the task. What you rather might want to do is to have different custom task implementations if you need to have different logic. In the consuming build script (the one that creates the enhanced task) you only want to provide values for certain properties configures these tasks.
I understand. But in this particular situation I want to have Closure property in my task. Gradle tasks are supposed to be POGOs or any JVM class. So when written in Groovy I expected default Groovy closure semantics: running closure with unnamed () invocation should be exactly as running ‘call()’ method. Now I need to explicitly write call() invocations to make it working.
For each task property ‘foo’, Gradle adds a method ‘foo’ that delegates to ‘setFoo’. So ‘foo()’ is the same as ‘setFoo()’, and since it’s missing an argument, Groovy adds a ‘null’. If you want to prevent this from happening, you can add your own ‘foo’ method that delegates to ‘foo.call()’.