Ahmed Hamouda
10/21/2024, 10:11 AMtasks.register<Copy>("unpackDependency") {
from(zipTree(configurations.runtimeClasspath.get().filter {
it.name.startsWith("party") && it.name.endsWith(".jar")
}.singleFile)) {
include("**/*.yaml")
exclude("**/api-import-party-v1.yaml")
}
includeEmptyDirs = false
into(unpackedDependencyDirectory)
}
My question is there a way to execute this task during the execution phase rather than resolving the dependencies in the configuration phase?
I tried using doFirst but keep getting: You cannot add child specs at execution time and I think it is because of using the from commandSergej Koščejev
10/21/2024, 10:37 AMunpackDependency.flatMap { it.outputDirectory } (where unpackDependency is the result of tasks.register). Have you tried that?Ahmed Hamouda
10/21/2024, 11:03 AMunpackDependency.flatMap { it.outputDirectory } ? By keeping the task as it is, it will still be executed at configuration time right?
I changed to this to avoid that:
tasks.register<Copy>("unpackDependency") {
val runtimeClasspath: FileCollection = configurations.runtimeClasspath.get()
from(runtimeClasspath)
doFirst {
from(zipTree(runtimeClasspath.single {
it.name.startsWith("party") && it.name.endsWith(".jar")
})) {
include("**/*.yaml")
exclude("**/api-import-party-v1.yaml")
}
}
into(unpackedDependencyDirectory)
}Sergej Koščejev
10/21/2024, 11:04 AMAhmed Hamouda
10/21/2024, 11:05 AMconfigurations.runtimeClasspath.get().filter results in resolving the dependencies at configuration time, and that what I want to avoid.Sergej Koščejev
10/21/2024, 11:08 AMFileCollection#matching could help too (instead of filter). Or maybe simply wrapping the whole zipTree(…) in a lambda could be enough, from({ zipTree(…)… })Ahmed Hamouda
10/21/2024, 11:42 AMzipTree still resolves the dependencies. Do u mind sharing the docs for creating a separate configuration.Sergej Koščejev
10/21/2024, 11:51 AMAhmed Hamouda
10/21/2024, 12:35 PMVampire
10/21/2024, 1:45 PMCopy, but inside the doLast { ... } a copy { ... }. But in that case make sure to also properly define the task inputs and outputs separately.
Besides that, Copy / copy is almost never what you want, but usually you should use Sync / sync.
And another thing to consider is, that this sounds more like a use-case for an artifact transform than a task.Ahmed Hamouda
10/21/2024, 2:10 PM