Tasks with public fields can't be annotated with @InputFile/@OutputFile/


(David Pärsson) #1

Assigning input/output file annotations to public fields will not make the fields be inputs/outputs, when there are no getters defined, as below.

class MyTask extends DefaultTask {
        @OutputFile
    public File outputFile
        @InputFiles
    public FileCollection inputFiles
        @TaskAction
    def doSomething() {
        // ...
    }
}

It would be very helpful if Gradle at least could fail the build when/if this is detected.

Removing the “public” keyword from the field declaration will make everything work as expected.


(Peter Niederwieser) #2

I think the problem is that Gradle initially looks for getters rather than fields. A Groovy property declaration (‘File outputFile’) generates a getter, whereas a field declaration (‘public File outputFile’) doesn’t. As it can be difficult to make sense of this, I’ve raised GRADLE-3043.


(David Pärsson) #3

Thank you!