This message was deleted.
# community-support
s
This message was deleted.
v
Ad-hoc task, or proper task class?
m
Proper task class
v
Then have a property, most probably of type
RegularFileProperty
that you annotate with
@InputFile
m
Will it work also if the file does not exists?
v
But actually iirc if you configure something, it must exist. You can add
@Optional
but that means it does not have to be configured. If it is configured, it must still exist. If you want to support configuring a path but not requiring it to exist you have to do it differently, like having it
@Internal
and then having a derived one that is
@InputFile
and
@Optional
where the provider is empty if the file does not exist.
Something like (untested)
Copy code
abstract class MyTask : DefaultTask() {
    @get:Internal
    abstract val inputFile: RegularFileProperty

    @get:Optional
    @get:InputFile
    val optionalInputFile = inputFile.map {
        if (it.asFile.isFile) it else null 
    }
}
m
I’ll give it a try, thanks a lot!!
👌 1