Up-To-Date check ignores @Input-annotated boolean properties

(Mike Meessen) #1


I have a task (written in Java, wrapped in a Plugin) that has a couple of boolean configuration flags that affect the files that are being generated by that task. I have annotated the boolean configuration properties in the task class like so:

    private Boolean featureEnabled = true;

Configuring the task in build.gradle:

generateSomeSource {
    featureEnabled = true

The problem is that gradle considers my task up-to-date and doesn’t run it, even if I change the configuration flag in build.gradle.

I have generated public accessor methods in the task class, I tried to annotate the getter instead of the field and I tried primitive “boolean” and Object “Boolean”. Nothing seems to work. If I use a java.lang.String instead of the booleans, gradle behaves as expected.

Is that a bug? Should I file a jira ticket? Or am I missing something?

Thanks in advance, Mike

(René Groeschke) #2

Hi Mike, this works for me just fine. Can you provide more details about your task. What other annotations do you use?

regards, René

(Mike Meessen) #3

Hi Rene, thanks for the quick reply.

I’m using quite a few other annotations, here’s an outline of the task:

public class MyGeneratorTask extends SourceTask {
    private File javaOutputDirectory;
    private File resourcesOutputDirectory;
    private File reportFile;
    private FileCollection compileClasspath;
    private Boolean feature1Enabled = true;
    private Boolean feature2Enabled = true;
    private Boolean feature3Enabled = false;
    public void generate() {

I’m afraid this won’t be very helpful for you. But the fact that it works as expected for you hints at an error on my side. I’ll have to hunt down the issue tomorrow, starting with an empty task. I’ll report back when I find something :wink:

Regards, Mike

(Peter Niederwieser) #4

Which Gradle version?

(Mike Meessen) #5

milestone-7 as well as milestone-8a

(Mike Meessen) #6

I finally found the issue!

I started off the task class with primitive boolean fields and generated the accessors for that field. The generated methods were:

    private boolean feature1Enabled = true;
      public boolean isFeature1Enabled() {
        return feature1Enabled;
      public void setFeature1Enabled(boolean boolean1Enabled) {
        this.feature1Enabled = boolean1Enabled;

Apparently, gradle ignores the @Input annotation if it doesn’t find a method starting with “get” (note the getter method name “isFeature1Enabled” vs. “getFeature1Enabled”).

Since the JavaBean Spec ( http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf ) explicitely allows the “is” notation (in section 8.3.2) and IDEs like Eclipse generate boolean getters with “is…”, I think this should be considered a gradle bug.

Best regards, Mike

(Peter Niederwieser) #7

I’ve created GRADLE-2115 for this.