Marcin Robaczyński
03/22/2024, 1:02 PM@Option but unless I invoke each task with their own option provided it won't work. Calling group task will fail as that Option is not registered for it. I know on alternative would be to use a project property but that would enforce project getting reconfigured which I'd rather avoid.
Running ./gradlew taskToRunThemAll invokes all of child tasks (myTaskMain, myTaskTest etc).
This will work fine:
./gradlew myTaskMain --my-input=foo myTaskTest --my-input=foo
This will fail as there is no option with the same name declared for the group task:
./gradlew taskToRunThemAll --my-input=foo
If I do create another task type and add my-input option to it, it will consume it and the parameter won't be shared anyway.
class MyPlugin : Plugin<Project> {
override fun apply(target: Project) {
val extension = target.extensions.getByType(KotlinProjectExtension::class.java)
val perSourceTask = extension.sourceSets.all { set ->
val dirs = set.kotlin.sourceDirectories.toList()
val taskName = "myTask${set.name.capitalized()}"
target.tasks.register(taskName, SomeSourceTask::class.java) {
it.setSource(dirs)
}
}
val topLevelTask = target.tasks.register("taskToRunThemAll")
topLevelTask.configure { it.dependsOn(perSourceTask)
}
}
abstract class SomeSourceTask : SourceTask() {
@get:Option(
option = "my-input",
description = "..."
)
@get:Input
abstract val myInput: Property<String>
}Marcin Robaczyński
03/22/2024, 1:04 PMtasks.withType(SomeSourceTask::class.java).configureEach {
topLevelTask.finalizedBy(it)
}Adam
03/22/2024, 2:31 PMtarget.providers.gradleProperty("myInput"). And then you can set a default value in gradle.properties, or pass one in ./gradlew taskToRunThemAll -PmyInput=fooMarcin Robaczyński
03/22/2024, 2:32 PMVampire
03/22/2024, 10:32 PM