Skip to content

Commit 35351a7

Browse files
committed
Lazily initialize GitRatchetGradle to avoid loading JGit at configuration time
GitRatchetGradle is instantiated eagerly when SpotlessTaskService is created, which happens during Gradle configuration. Its static initializer installs a custom JGit SystemReader that reads ~/.gitconfig. This causes Gradle's configuration cache to fingerprint the file even when no Spotless tasks are requested. Defer instantiation to getRatchet(), which is only called during task execution. This avoids loading JGit classes and reading git config files at configuration time.
1 parent 46b8770 commit 35351a7

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ void registerApplyAlreadyRan(SpotlessApply task) {
9999
}
100100

101101
// <GitRatchet>
102-
private final GitRatchetGradle ratchet = new GitRatchetGradle();
102+
private GitRatchetGradle ratchet;
103103

104104
GitRatchetGradle getRatchet() {
105+
if (ratchet == null) {
106+
ratchet = new GitRatchetGradle();
107+
}
105108
return ratchet;
106109
}
107110

@@ -112,7 +115,9 @@ public void onFinish(FinishEvent var1) {
112115

113116
@Override
114117
public void close() throws Exception {
115-
ratchet.close();
118+
if (ratchet != null) {
119+
ratchet.close();
120+
}
116121
}
117122
// </GitRatchet>
118123

0 commit comments

Comments
 (0)