Ken Yee
04/29/2025, 7:18 PMtasks.register("updateModuleCapabilitiesIndex") {
val watchFiles = fileTree(project.rootDir) {
include("**/build.gradle", "**/build.gradle.kts")
}.files
val moduleIndexFile = "${layout.buildDirectory.get()}/moduleCapabilities.json"
val moduleIndexCmdLine = listOf(
"./gradlew",
"...",
)
inputs.files(watchFiles)
doLast {
providers.exec {
commandLine = moduleIndexCmdLine
}
}
dependsOn("build")
}
Command removed for simplification, but I'm trying to write something that parses the gradle files and then saves the info into another file in a cacheable way.
The doLast{...} bit unfortunately contains a gradle script which is not serializable... Tried to search in this slack but configuration cache gets a lot of unrelated hits 😂Martin
04/29/2025, 7:25 PMproviders
in a local variable that can be captured by the lambda maybe? Is this what pulls the Gradle script?Ken Yee
04/29/2025, 7:26 PMMartin
04/29/2025, 7:28 PMtasks.register("hello") {
val providers = project.providers
doLast {
providers.exec {
commandLine = listOf("echo", "hello world")
}
}
}
This works for meVampire
04/29/2025, 7:31 PMexec
. :-)Ken Yee
04/29/2025, 7:37 PMephemient
04/29/2025, 7:37 PMExecOperations
injected,
abstract class UpdateModuleCapabilitiesIndex : DefaultTask() {
@get:Inject
abstract val execOperations: ExecOperations
@TaskAction
fun exec() {
execOperations.exec { ... }
}
}
val updateModuleCapabilitiesIndex by tasks.registering(UpdateModuleCapabilitiesIndex::class)
ephemient
04/29/2025, 7:39 PMKen Yee
04/29/2025, 7:39 PMMartin
04/29/2025, 7:39 PMKen Yee
04/29/2025, 8:00 PMMikhail Lopatkin
04/29/2025, 9:35 PMproviders.exec
for the external process to run, this thing is lazy. Also, its intended use is to capture the standard output of the process. ExecOperations is a better choice in the described use case.Ben Berman
07/09/2025, 10:10 PMexec
?Vampire
07/09/2025, 11:17 PMproviders.exec
or ExecOperations#exec
or a task of type Exec
.