Replace dependsOn with source set configuration#49537
Replace dependsOn with source set configuration#49537Sineaggi wants to merge 2 commits intospring-projects:mainfrom
Conversation
Signed-off-by: Clayton Walker <clayton.m.walker@gmail.com>
9f1c3b1 to
c10796f
Compare
237b665 to
4520150
Compare
|
Thanks for the PR. Unfortunately, this approach will leave the main source set with an output dir configured as a src dir. I think that cycle is likely to cause problems. Please open an issue with a minimal sample that reproduces the failure described above so that we can investigate some alternatives. Given the javadoc of |
Can you explain what this means? That's normally exactly how generated sources should be hooked up in gradle, you have a generating task and it's output directory is either added to the java srcDirs or the resources srcDirs. This way any users of the output of classes correctly wire up the producing tasks. |
|
Simplest reproducer: springBoot {
buildInfo()
}
tasks.register("resourceProcessor") {
// this task does *something* with the resources
val resourceProcessorInput = objects.directoryProperty()
resourceProcessorInput.fileProvider(tasks.processResources.map { it.destinationDir })
inputs.dir(resourceProcessorInput)
doFirst {
println(resourceProcessorInput.get().asFile)
}
}Now run I should instead be able to run resourceProcessor and see all resources in the build resources ouput directory. |
When |
|
Ah, ok I think I see what's happening. The spring boot plugin is writing directly into the output resources directory. That's owned by As I understand it, the |
This is what we tried doing in the meantime, however we'd need something like this to make it all correct. springBoot {
buildInfo {
destinationDir = layout.buildDirectory.dir("generated/boot-build-info")
doLast {
// destinationDir needs to point to the directory containing META-INF, but the bootBuildInfo task writes directly into destinationDir.
val path = destinationDir.get().asFile.toPath()
Files.move(
path.resolve("build-info.properties"),
Files.createDirectories(path.resolve("META-INF")).resolve("build-info.properties"),
StandardCopyOption.REPLACE_EXISTING
)
}
}
}
sourceSets.main {
resources.srcDirs(tasks.named("bootBuildInfo"))
} |
Done! |
Fixes the use of
dependsOnin the spring boot gradle plugin. See Best Practices for Tasks - Avoid DependsOnUnfortunately Gradle isn't smart enough to know that a dependsOn allows other tasks that might use sourceset outputs as their inputs, we should use Gradle's implicit input/output tracking instead.
Without this, if one uses for example a task that uses the main output resources, such as Google's protobuf gradle plugin, and another task that shares resources like test fixtures or additional test suites, you'll end up with issues with undefined dependencies.