Sergej Koščejev
01/28/2025, 9:18 AMMartin
01/28/2025, 9:21 AMSergej Koščejev
01/28/2025, 9:22 AMMartin
01/28/2025, 9:22 AMMartin
01/28/2025, 9:23 AMSergej Koščejev
01/28/2025, 9:23 AMSergej Koščejev
01/28/2025, 9:23 AMMartin
01/28/2025, 9:24 AMSergej Koščejev
01/28/2025, 9:24 AMMartin
01/28/2025, 9:24 AM@Optional
for outputs?Sergej Koščejev
01/28/2025, 9:25 AMSergej Koščejev
01/28/2025, 9:26 AMMartin
01/28/2025, 9:27 AMif
s in my code. Similarly I want some consistency in the tasks inputs/outputs.Martin
01/28/2025, 9:27 AMSergej Koščejev
01/28/2025, 9:29 AMMartin
01/28/2025, 9:32 AMSergej Koščejev
01/28/2025, 9:33 AMMartin
01/28/2025, 9:33 AMMartin
01/28/2025, 9:35 AMThomas Broyer
01/28/2025, 10:22 AM@Internal
properties and have an output property whose value is computed by the task depending on what it will do / have to do.Vampire
01/28/2025, 10:23 AMVampire
01/28/2025, 10:24 AMSergej Koščejev
01/28/2025, 10:25 AMVampire
01/28/2025, 10:28 AMVampire
01/28/2025, 10:28 AMThomas Broyer
01/28/2025, 10:36 AMabstract class MyTask : DefaultTask() {
@get:Internal
abstract val fooDir: DirectoryProperty
@get:Internal
abstract val barDir: DirectoryProperty
@get:Input
abstract val useFoo: Property<Boolean>
@get:OutputDirectory
val outputDirectory: DirectoryProperty
get() = if (useFoo.getOrElse(false)) fooDir else barDir
@TaskAction
fun run() {}
}
tasks {
register<MyTask>("fooOrBar") {
fooDir = layout.buildDirectory.dir("foo")
barDir = layout.buildDirectory.dir("bar")
useFoo = false
}
}
Vampire
01/28/2025, 10:37 AMVampire
01/28/2025, 10:37 AMVampire
01/28/2025, 10:37 AMSergej Koščejev
01/28/2025, 10:37 AMSergej Koščejev
01/28/2025, 10:38 AMThomas Broyer
01/28/2025, 10:59 AMabstract class MyTask @Inject constructor(
private val providers: ProviderFactory
): DefaultTask() {
@get:Internal
abstract val fooDir: DirectoryProperty
@get:Internal
abstract val barDir: DirectoryProperty
@get:InputFile
abstract val inputFile: RegularFileProperty
@get:Internal
val inputFileContent: String by lazy { inputFile.get().asFile.readText() }
@get:OutputDirectory
val outputDirectory: Provider<Directory>
get() = providers.provider { if (inputFileContent == "foo") fooDir.get() else barDir.get() }
@TaskAction
fun run() {}
}
tasks {
register<MyTask>("fooOrBar") {
fooDir = layout.buildDirectory.dir("foo")
barDir = layout.buildDirectory.dir("bar")
inputFile = layout.projectDirectory.file("input")
}
}
Of course determining whether you use fooDir
or barDir
needs to be relatively lightweight, as you pay that price every time, to compute whether the task is up-to-date or not, to decide whether to run it or not