According to the userguide’s Lazy Configuration section:
Note that Groovy Gradle DSL will generate setter methods for each
Property
-typed property in a task implementation. These setter methods allow you to configure the property using the assignment (=
) operator as a convenience.
This appears to not function when the task class’s field is explicitly public
.
class PropTest extends DefaultTask {
@Input
final Property<String> message = project.objects.property( String )
/* does not work (Cannot cast object 'hi' with class 'java.lang.String' to class 'org.gradle.api.provider.Property')
public final Property<String> message = project.objects.property( String )
*/
@TaskAction
void doWork() {
println message.get()
}
}
task hi( type: PropTest ) {
message = "hi"
}
I noticed this when I tried porting a task class from the build script into a java class in a plugin. Is this a bug or is there missing documentation about the limitations?