Skip to content

Commit 0980fa8

Browse files
committed
Use Gradle user home directory for downloading biome, fixes diffplug#2187
Use the Gradle user home directory by default for the download directory for the biome executable. Previously, the plugin tried to use Maven's home directory, which is not always accessible by a Gradle plugin. According to the [Gradle docs](https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api.invocation/-gradle/get-gradle-user-home-dir.html), the user home directory > is used to cache downloaded resources, compiled build scripts and so on. From that description, it seems to me to be the proper location for the biome executable.
1 parent 1b79196 commit 0980fa8

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

plugin-gradle/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66

7+
* Use the Gradle user home directory by default for the download directory for the biome executable. Previously, the
8+
plugin tried to use Maven's home directory, which is not always accessible by a Gradle plugin. ([#2187](https://github.com/diffplug/spotless/issues/2187))
9+
710
## [7.0.0.BETA2] - 2024-08-25
811
### Changed
912
* Support toning down sortPom logging. ([#2185](https://github.com/diffplug/spotless/pull/2185))

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
import static java.util.Objects.requireNonNull;
1919

2020
import java.io.File;
21-
import java.nio.file.Path;
2221
import java.nio.file.Paths;
2322
import java.util.function.Consumer;
2423

2524
import javax.annotation.Nullable;
2625

2726
import org.gradle.api.Project;
28-
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
2927

3028
import com.diffplug.spotless.FormatterStep;
3129
import com.diffplug.spotless.biome.BiomeFlavor;
@@ -208,23 +206,10 @@ protected void replaceStep() {
208206
* @return The directory for storing shared data.
209207
*/
210208
private File findDataDir() {
211-
var currentRepo = project.getRepositories().stream().filter(r -> r instanceof MavenArtifactRepository)
212-
.map(r -> (MavenArtifactRepository) r).filter(r -> "file".equals(r.getUrl().getScheme())).findAny()
213-
.orElse(null);
214-
// Temporarily add mavenLocal() repository to get its file URL
215-
var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo
216-
: project.getRepositories().mavenLocal();
217-
try {
218-
// e.g. ~/.m2/repository/
219-
var repoPath = Path.of(localRepo.getUrl());
220-
var dataPath = repoPath.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data");
221-
return dataPath.toAbsolutePath().toFile();
222-
} finally {
223-
// Remove mavenLocal() repository again if it was not part of the project
224-
if (currentRepo == null) {
225-
project.getRepositories().remove(localRepo);
226-
}
227-
}
209+
// e.g. ~/.gradle/
210+
var userHomeDir = project.getGradle().getGradleUserHomeDir().toPath();
211+
var dataPath = userHomeDir.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data");
212+
return dataPath.toAbsolutePath().toFile();
228213
}
229214

230215
/**
@@ -247,7 +232,7 @@ private BiomeStep newBuilder() {
247232
/**
248233
* Resolves the path to the Biome executable. When the path is only a file name,
249234
* do not perform any resolution and interpret it as a command that must be on
250-
* the user's path. Otherwise resolve the executable path against the project's
235+
* the user's path. Otherwise, resolve the executable path against the project's
251236
* base directory.
252237
*
253238
* @return The resolved path to the Biome executable.

0 commit comments

Comments
 (0)