@InputFile annotation - should path be relative or absolute


(Steve Cohen) #1

I’ve tried using a relative file path assuming a base of the root directory of the project and it fails with not being able to find the file.

How would I use the @InputFile annotation specifying a path relative to the project’s base directory?


(Mark Vieira) #2

The @InputFile annotation has to be placed on an instance of File. Relative vs absolute is only an issue when you are creating the file instance, in which case you should be using the Project.file() method.

class MyTask extends DefaultTask {
    @InputFile
    File myInput
}

task foo(type: MyTask) {
    myInput = file('dir/relativeTo/projectDir/input.txt')
}