hello all, I've been running into a strange issue ...
# community-support
w
hello all, I've been running into a strange issue with the gradle cache in combination with a certain plugin. The second time this file should come from the gradle cache, it's no longer there. Lucky for me someone else already figured out that this problem was introduced somewhere between gradle 8.5 and 8.6. So I thought:
git bisect
to the rescue. But now I've figured out the "offending commit": https://github.com/gradle/gradle/commit/deefa5287670c26fd046ea19250904829063682c, I'm still having problems figuring out why gradle doesn't want to generate the file after first getting it properly from the cache... First run is with
--rerun-tasks
to make sure it's not getting stuff from the cache. And then the first attempt it works, second attempt it doesn't. --edit Now the question is: how do I continue from here? I've tried to attach the debugger to the daemon, and the file is reported as a MissingFileSnapshot in both runs. So the difference is also not there. But I'm struggling to figure out where to go next. Should I just open a bug report? But seeing 3000 open issues, I would like to be a bit more helpful.
Copy code
❯ ./gradlew clean assemble --rerun-tasks --console=plain && ls my-module/build/resources/main/git.properties
Starting a Gradle Daemon, 6 stopped Daemons could not be reused, use --status for details
> Task :my-module:clean
> Task :my-module:compileJava NO-SOURCE
> Task :my-module:generateGitProperties
> Task :my-module:processResources
> Task :my-module:classes
> Task :my-module:jar
> Task :my-module:assemble

BUILD SUCCESSFUL in 2s
4 actionable tasks: 4 executed
my-module/build/resources/main/git.properties
❯ ./gradlew clean assemble --console=plain && ls my-module/build/resources/main/git.properties
> Task :my-module:clean
> Task :my-module:compileJava NO-SOURCE
> Task :my-module:generateGitProperties FROM-CACHE
> Task :my-module:processResources
> Task :my-module:classes
> Task :my-module:jar
> Task :my-module:assemble

BUILD SUCCESSFUL in 352ms
4 actionable tasks: 3 executed, 1 from cache
my-module/build/resources/main/git.properties
❯ ./gradlew clean assemble --console=plain && ls my-module/build/resources/main/git.properties
> Task :my-module:clean
> Task :my-module:compileJava NO-SOURCE
> Task :my-module:generateGitProperties FROM-CACHE
> Task :my-module:processResources
> Task :my-module:classes
> Task :my-module:jar
> Task :my-module:assemble

BUILD SUCCESSFUL in 330ms
4 actionable tasks: 3 executed, 1 from cache
ls: my-module/build/resources/main/git.properties: No such file or directory
I've raised an issue for now. But still would have liked to be able to find the root cause myself. Only difference I can see in the build scans is that the failing situation claims that the task is not on the critical path.
e
do things work if you
Copy code
sourceSets {
    main {
        resources.srcDir(tasks.named("generateGitProperties").map { layout.buildDirectory.dir("resources/main").get() })
    }
}
?
w
Thanks for the suggestion, but that breaks the build since it then adds test.txt twice:
Copy code
Execution failed for task ':processResources'.
> Entry test.txt is a duplicate but no duplicate handling strategy has been set. Please refer to <https://docs.gradle.org/8.14.3/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy> for details.
e
are you setting
gitPropertiesResourceDir
? try without, so that it avoids that bit of logic in the plugin
v
The problem is not Gradle but indeed that horribly bad-practice programmed plugin and very bad default values. In your reproducer the output of
generateGitProperties
is
build/resources/main/git.properties
and the output of
processResources
is
build/resources/main
. This is overlapping outputs and that is always prone to breaking stuff. It just happens to sometimes work because of several other bad practices that plugin is doing like making the
classes
task depend on
generateGitProperties
and registering
build/resources/main
as resources srcDir of the
main
source set which means the
processResources
task is also self-copying that directory and so on besides quite some other bad practices. In that state I would very highly recommend not applying that plugin ever to any build. To avoid the most-problematic non-sense of that plugin, you need to make sure
gitPropertiesResourceDir
is not set as @ephemient said, additionally set
gitPropertiesDir = layout.buildDirectory.dir("generated/resources/git")
to break the overlapping task outputs and add
sourceSets { main { resources.srcDir(tasks.generateGitProperties.map { it.output.map { it.asFile.parentFile } }) } }
to properly declare the task output as resource source including the necessary implicit task dependency. With that the various bugs of the plugin should be avoided / worked-around.
And it only happens if you have some resource because without the resource, the
processResources
task is never run
w
are you setting
gitPropertiesResourceDir
? try without, so that it avoids that bit of logic in the plugin
We are not setting it in the reproducer. But I'll try the solution provided in the ticket. Thanks for helping me here!
In that state I would very highly recommend not applying that plugin ever to any build.
I'll forward this advice.
v
Ah, sorry, meant to delete that sentence
With the work-around I provided (also in the ticket and approved by the Gradle folk there as the better work-around) it is ok to apply the plugin.
But it should really be fixed of the various bad practices and broken default setup
w
Yeah, that sounds like the proper improvement in the git.properties plugin. I hoped that I could use
git bisect
to actually determine the cause of a bug. Guess better luck next time.
I've removed my reference to your do not use this at all in my github comment.
👌 1