jmongard / Git.SemVersioning.Gradle

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin
Apache License 2.0
38 stars 4 forks source link

Incompatibility with Gradle's configuration cache #50

Closed sschuberth closed 4 months ago

sschuberth commented 4 months ago

Since Gradle 8.1 the configuration cache is stable and can be enabled e.g. via --configuration-cache. Doing so with a project that uses this plugin results in

org.gradle.api.InvalidUserCodeException: Starting an external process '/usr/bin/git --version' during configuration time is unsupported.
    at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1$build$diagnostics$1.get(DefaultProblemFactory.kt:79)
    at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1$build$diagnostics$1.get(DefaultProblemFactory.kt:79)
    at org.gradle.internal.problems.DefaultProblemDiagnosticsFactory$DefaultProblemStream.getImplicitThrowable(DefaultProblemDiagnosticsFactory.java:147)
    at org.gradle.internal.problems.DefaultProblemDiagnosticsFactory$DefaultProblemStream.forCurrentCaller(DefaultProblemDiagnosticsFactory.java:136)
    at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1.build(DefaultProblemFactory.kt:79)
    at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onExternalProcessStarted(ConfigurationCacheProblemsListener.kt:98)
    at org.gradle.configurationcache.InstrumentedInputAccessListener.externalProcessStarted(InstrumentedInputAccessListener.kt:111)
    at org.gradle.internal.classpath.Instrumented.externalProcessStarted(Instrumented.java:457)
    at org.gradle.internal.classpath.Instrumented.externalProcessStarted(Instrumented.java:465)
    at org.gradle.internal.classpath.Instrumented.start(Instrumented.java:319)
    at org.eclipse.jgit.util.FS.readPipe(FS.java:1405)
    at org.eclipse.jgit.util.FS.readPipe(FS.java:1367)
    at org.eclipse.jgit.util.FS.discoverGitSystemConfig(FS.java:1556)
    at org.eclipse.jgit.util.FS.getGitSystemConfig(FS.java:1653)
    at org.eclipse.jgit.util.SystemReader$Default.openSystemConfig(SystemReader.java:107)
    at org.eclipse.jgit.util.SystemReader.getSystemConfig(SystemReader.java:379)
    at org.eclipse.jgit.util.SystemReader.getUserConfig(SystemReader.java:327)
    at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:162)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:627)
    at git.semver.plugin.scm.GitProvider.getRepository(GitProvider.kt:105)
    at git.semver.plugin.scm.GitProvider.getSemVersion$git_semver_plugin(GitProvider.kt:26)
    at git.semver.plugin.gradle.GitSemverPluginExtension$semVersion$2.invoke(GitSemverPluginExtension.kt:14)
    at git.semver.plugin.gradle.GitSemverPluginExtension$semVersion$2.invoke(GitSemverPluginExtension.kt:14)

So the culprit actually is JGit, which falls back to calling the git CLI to find the Git system configuration. This can be worked around by setting the GIT_CONFIG_NOSYSTEM environment variable, but this is a bit cumbersome to do from inside a Gradle build, see e.g. the solution at https://github.com/oss-review-toolkit/ort/commit/9a0c0b1546fc3bdcb299a6c7ed1c91c72c81de52.

Another solution as mentioned in the commit linked above is to use a Gradle ValueSource. This is the approach I've implemented in the smae project as linked above later, see https://github.com/oss-review-toolkit/ort/commit/855440d83b233f9ba1fb3501c52ae7790d4efccb.

@jmongard any opinion about which approach to prefer?

jmongard commented 4 months ago

Yes, I am aware. I'm trying to figure out how to wrap the functionality in a ValueSource to make it work

sschuberth commented 4 months ago

I'm trying to figure out how to wrap the functionality in a ValueSource to make it work

The code from the PR I've linked could be helpful here.

sschuberth commented 4 months ago

Confirmed to be fixed with release 0.12.0.

jmongard commented 4 months ago

I modified the code to use two ValueSources. One for SemVersion (without SHA and commit count) and one for SemInfoVersion. I hope this will make it so that if you make a commit that does not change the version number and only access the version property that wont invalidate the configuration cache.