hello, I have a problem with Gradle 8.6 and the ou...
# caching
a
hello, I have a problem with Gradle 8.6 and the output of a
WriteProperties
task which seems to be not restored from the build cache. This happens not consistently. I get
Copy code
> Task :gradle-plugins:config-gradle-plugin:props FROM-CACHE
Appending implementation to build cache key: org.gradle.api.tasks.WriteProperties_Decorated@7f188f326239382116310befb40da15f
Appending additional implementation to build cache key: org.gradle.api.tasks.WriteProperties_Decorated@7f188f326239382116310befb40da15f
Appending input value fingerprint for 'comment' to build cache key: f6bd6b3389b872033d462029172c8612
Appending input value fingerprint for 'encoding' to build cache key: a01a9ddf322da930e94b377f84683032
Appending input value fingerprint for 'lineSeparator' to build cache key: d0608bef942477d145a034e0902d2ff8
Appending input value fingerprint for 'properties' to build cache key: 3a19c1074096c79765360687c2843f48
Appending output property name to build cache key: destinationFile
Build cache key for task ':gradle-plugins:config-gradle-plugin:props' is 3edb56921b5aba38b2f0c0e8e1ab8a9a
but then there is no such file in the directory where it should be restored. This does not happen with Gradle 8.5 Do you have any hints to follow?
v
Are you sure the file is not restored from build cache and not maybe deleted from some later action?
a
I am not. Is it possible the file is not restored because the directory where it should be restored to does not exist yet?
v
I would doubt that actually
a
The build cache entry contains this:
Copy code
METADATA
tree-destinationFile
the content of
tree-destinationFile
is the properties file written by the task. Is this correct? The task is definition is
Copy code
val props = tasks.register<WriteProperties>("props") {
    destinationFile.set(file("${project.buildDir}/resources/main/${project.name}.properties"))
    property("version", project.version)
}
v
That's a pretty bad idea actually. You are polluting the output directory of another task. This comes with many problems you really shouldn't do. I guess the
processResources
task - which effectively is like a
Sync
task - runs after the cache was restored and thus removes the file that should not be there and is considered a stale file from a previous run.
Each task should have dedicated output locations and tasks should never have overlapping outputs, or you come into hell. 🙂
Also, if some task gets resources for some cause, like the
sourcesJar
task will not ever see your file or have the necessary task dependency implicitly.
Instead write the file to a dedicated location, and register the task with
Copy code
sourceSets {
    main {
        resources {
            srcDir(propsTask)
        }
    }
}
Or actually, don't use a separate task. For cases like this I usually just have a properties file in
src/main/resources
with placeholders and configure the
processResources
task to
expand(...)
the placeholder. This imho has various advantages, except if you also need that file dedicated for some other task.
a
thanks @Vampire I am trying the
expand
approach 😄
👌 1