Input and Output annotations to work for tasks implemented in Java


(Vincent Cantin) #1

It seems that it is not currently (v1.6) possible to use annotations like @OutputDirectory in Java classes (the annotations are ignored).

It would be nice to have this supported. At least, write it somewhere that it is only supported in Groovy - it took me 2 hours to figure out why it was not working.


(Luke Daley) #2

It definitely is supported; many tasks are implemented in Java.

What did you try?


(Vincent Cantin) #3

I just took a look at the source files in Gradle, and the only difference I see with my Java file is that I was annotating public fields while Gradle is mostly using annotations on methods.

I will run a test tonight and post a link to a gist here.


(Vincent Cantin) #4

I think I found a bug in Gradle. Please take a look at my test project: https://github.com/green-coder/gradle-annotation-bug/blob/master/buildSrc/src/main/groovy/mypackage/MyTask.java

The annotations are ignored when applied on the fields of java classes.


(Vincent Cantin) #5

I would like to bring some attention to this issue.


(Peter Niederwieser) #6

I’m not sure if the bug is in the implementation or documentation (which says that annotations can also be placed on fields). For now, just put them on the getter methods. That’s what all of Gradle’s own tasks do.


(Luke Daley) #7

I’ve raised GRADLE-2856 for this.