Class ConfigCacheSafeSystemReader

java.lang.Object
io.github.duckasteroid.gradle.versioning.ConfigCacheSafeSystemReader

public final class ConfigCacheSafeSystemReader extends Object
Constructing a JGit Repository (via RepositoryBuilder().build()) makes JGit shell out to the real git binary (git --version, then git config --system --show-origin --list -z) the first time it needs the system-level git config - SystemReader.getSystemConfig() -> openSystemConfig() -> FS.discoverGitSystemConfig() -> FS.readPipe() - because there's no portable file-path convention for where that config lives. That's an external process started during Gradle configuration time wherever a Repository is built eagerly (as opposed to inside a task's doLast), which the configuration cache rejects outright.

Neither VersionPlugin nor VersionResolver ever read system/global git config - only remote.origin.url from the repo's own local config, plus refs/tags/HEAD - so it's safe to tell JGit to skip that layer entirely.

JGit's own SystemReader$Default#openSystemConfig already has a fast path for this: it checks the GIT_CONFIG_NOSYSTEM environment variable (the same one the real git CLI honours) and, if set, skips straight to an empty, no-op config instead of shelling out. The obvious way to reach that fast path would be overriding getenv("GIT_CONFIG_NOSYSTEM") on a SystemReader.Delegate - but Delegate#openSystemConfig forwards directly to the wrapped reader's openSystemConfig, which then calls getenv on itself, not back up through the wrapper - so a getenv override alone is silently never consulted. Overriding openSystemConfig itself, below, sidesteps that dispatch trap entirely and is also just a more direct expression of "skip system config" than faking an environment variable to trigger a side path.

SystemReader.getInstance()/setInstance() are JVM-wide, so this must be called once, defensively, immediately before any code in this project constructs a RepositoryBuilder-based Repository - it's idempotent and cheap to call more than once.

  • Method Details

    • install

      public static void install()