From 87c1d0f6f41abd529362584a06ce973ff9b199e8 Mon Sep 17 00:00:00 2001 From: Joshua Soberg Date: Sat, 2 Aug 2025 12:03:21 -0400 Subject: [PATCH 1/2] Set the root dir before execution time, to make this task compatible with the Gradle configuration cache. --- .../com/diffplug/gradle/spotless/SpotlessExtensionImpl.java | 1 + .../gradle/spotless/SpotlessInstallPrePushHookTask.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java index 53b7b011a1..05fc60ebd7 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java @@ -39,6 +39,7 @@ public SpotlessExtensionImpl(Project project) { task.setGroup(TASK_GROUP); // no description on purpose }); rootInstallPreHook = project.getTasks().register(EXTENSION + INSTALL_GIT_PRE_PUSH_HOOK, SpotlessInstallPrePushHookTask.class, task -> { + task.rootDir = project.getRootDir(); task.setGroup(BUILD_SETUP_TASK_GROUP); task.setDescription(INSTALL_GIT_PRE_PUSH_HOOK_DESCRIPTION); }); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessInstallPrePushHookTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessInstallPrePushHookTask.java index 3e59e94b0a..42652a0b1d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessInstallPrePushHookTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessInstallPrePushHookTask.java @@ -15,6 +15,8 @@ */ package com.diffplug.gradle.spotless; +import java.io.File; + import org.gradle.api.DefaultTask; import org.gradle.api.tasks.TaskAction; import org.gradle.work.DisableCachingByDefault; @@ -32,6 +34,8 @@ @DisableCachingByDefault(because = "not worth caching") public class SpotlessInstallPrePushHookTask extends DefaultTask { + File rootDir; + /** * Executes the task to install the Git pre-push hook. * @@ -60,7 +64,7 @@ public void error(String format, Object... arguments) { } }; - final var installer = new GitPrePushHookInstallerGradle(logger, getProject().getRootDir()); + final var installer = new GitPrePushHookInstallerGradle(logger, rootDir); installer.install(); } } From 526eb05ab8c7afb6dbd79759d554e44544a874ef Mon Sep 17 00:00:00 2001 From: Joshua Soberg Date: Sat, 2 Aug 2025 12:12:29 -0400 Subject: [PATCH 2/2] Updating changefiles as requested --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 38af879390..a48be57aeb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765)) * Bump default `google-java-format` version to latest `1.24.0` -> `1.28.0`. ([#2345](https://github.com/diffplug/spotless/pull/2345)) * Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555)) +* Make Git pre-push hook install task (`spotlessInstallGitPrePushHook`) compatible with the Gradle configuration cache. ([#2585](https://github.com/diffplug/spotless/issues/2585)) ## [3.3.1] - 2025-07-21 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 9e25b1d3d3..895b9bf47d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555)) ### Fixed * Respect system gitconfig when performing git operations ([#2404](https://github.com/diffplug/spotless/issues/2404)) +* Make Git pre-push hook install task (`spotlessInstallGitPrePushHook`) compatible with the Gradle configuration cache. ([#2585](https://github.com/diffplug/spotless/issues/2585)) ## [7.2.1] - 2025-07-21 ### Fixed