[GRADLE-2115] Up-To-Date check ignores @Input-annotated boolean properties Created: 22/Feb/12  Updated: 14/Sep/16  Resolved: 12/Jul/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 3.0-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Lóránt Pintér
Resolution: Fixed Votes: 0


 Description   

Hi,

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:

@Input
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



 Comments   
Comment by Gradle Forums [ 22/Feb/12 ]

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

regards,
René

Comment by Gradle Forums [ 22/Feb/12 ]

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 {

@OutputDirectory
private File javaOutputDirectory;

@OutputDirectory
private File resourcesOutputDirectory;

@OutputFile
private File reportFile;

@InputFiles
private FileCollection compileClasspath;

@Input
private Boolean feature1Enabled = true;

@Input
private Boolean feature2Enabled = true;

@Input
private Boolean feature3Enabled = false;

@TaskAction
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

Regards,
Mike

Comment by Gradle Forums [ 22/Feb/12 ]

Which Gradle version?

Comment by Gradle Forums [ 22/Feb/12 ]

milestone-7 as well as milestone-8a

Comment by Gradle Forums [ 22/Feb/12 ]

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:

@Input
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 ( [1]http://download.oracle.com/otn-pub/jc... ) 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
----------------------------------------------------------------------------------------
[1] http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf

Comment by Lóránt Pintér [ 12/Jul/16 ]

This has been resolved in 3.0.

Generated at Wed Jun 30 12:13:12 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.