Open sdavids opened 6 months ago
Interim solution?
It is possible to declare that a particular task is not compatible with the configuration cache via the Task.notCompatibleWithConfigurationCache() method.
Configuration cache problems found in tasks marked incompatible will no longer cause the build to fail.
https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:task_opt_out
Hi,
I see in the first snippet that you're using the version 2.8.2? Is that possible to try with version 3.1.0.
As for the cache configuration issue, I don't know how the call to the external command (git
) could be cached and if it even makes sense. So I agree with you that the least bad approach would maybe to mark it as not compatible with the cache.
What do you think?
$ mkdir /tmp/test && cd "$_"
$ gradle init --type java-library --java-version 21 --project-name test --dsl groovy --test-framework junit-jupiter --no-comments --no-incubating --quiet
$ perl -i -l -p -e "print \" id 'net.nemerosa.versioning' version '3.1.0'\" if $. == 4" lib/build.gradle
$ printf '\nversioning {}\nversion = versioning.info.full\n' >> lib/build.gradle
$ git init --quiet
$ git add -A
$ git commit --quiet -m "initial"
$ ./gradlew --configuration-cache --quiet clean
FAILURE: Build failed with an exception.
* Where:
Build file '/private/tmp/test/lib/build.gradle' line: 32
* What went wrong:
Configuration cache problems found in this build.
2 problems were found storing the configuration cache.
- Build file 'lib/build.gradle': external process started '/usr/local/bin/git --version'
See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Build file 'lib/build.gradle': external process started '/usr/local/bin/git config --system --show-origin --list -z'
See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:external_processes
See the complete report at file:///private/tmp/test/build/reports/configuration-cache/2cvh062oate61b7yhx8pzmmbf/ebyxie6m7vpbm2q7bw5v4bf88/configuration-cache-report.html
> Starting an external process '/usr/local/bin/git --version' during configuration time is unsupported.
> Starting an external process '/usr/local/bin/git config --system --show-origin --list -z' during configuration time is unsupported.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 5s
The example provided by the Gradle team wraps the git
call inside providers.exec
:
def gitVersion = providers.exec {
commandLine("git", "--version")
}.standardOutput.asText.get()
Maybe calls to SCMInfoService
should be wrapped in providers.exec
or calls to Grgit
and SVNClientManager
should be wrapped.
There is Gradle Roadmap item this issue might be added to ...
https://blog.gradle.org/road-to-gradle-9#configuration-cache-improvements
In Gradle 9.0, the Configuration Cache will be the preferred mode of execution, and turning it off will be deprecated.
Here is what another project using Grgit did:
I was able to work around this by wrapping my calls to versioning.info
in a provider:
val provider = project.provider {
// Intentionally skip cache (not sure if necessary though)
val info = versioning.computeInfo()
runCatching { info.tag ?: info.full }.getOrDefault("0.0.0")
}
project.version = provider.get()
configuration-cache-report.html
https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:external_processes