Howto use RegularFileProperty.convention()

(Eric Vantillard) #1

Hi,

in a custom task I have define a file property

open class SomeTask() : DefaultTask() {
    val somePath = project.objects.fileProperty()
}

I would like to add some convention

open class SomeTask() : DefaultTask() {
    val somePath = project.objects.fileProperty().convention(file("/some/path/here"))
}

but convention()require RegularFilePropertyas input type.

What is the idiomatic way to define a default value for a fileProperty ?

0 Likes

(Pierre) #2

Hello,

RegularFileProperty file = project.getObjects().fileProperty()
    .convention(project.getLayout().getProjectDirectory().file("some/path/here"));
// If default location is in build/some/path/here, use:
// project.getLayout().getBuildDirectory().file("some/path/here")

Note that API is still incubating, so it might evolve in the upcoming releases.

0 Likes