Skip to content

Commit a5c44dd

Browse files
authored
Fix the Gradle plugin not to break the clean task when Gradle's configuration cache is enabled (#797)
2 parents 95b7c5c + f92fbb8 commit a5c44dd

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

Diff for: plugin-gradle/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Fixed
7+
* Fixed the `clean` task when Gradle's configuration cache is enabled ([#796](https://github.com/diffplug/spotless/issues/796))
68

79
## [5.10.0] - 2021-02-09
810
### Added

Diff for: plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2021 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,16 +42,13 @@ public void apply(Project project) {
4242
project.getExtensions().create(SpotlessExtension.class, SpotlessExtension.EXTENSION, SpotlessExtensionImpl.class, project);
4343

4444
// clear spotless' cache when the user does a clean
45-
project.getTasks().named(BasePlugin.CLEAN_TASK_NAME).configure(clean -> {
46-
clean.doLast(unused -> {
47-
// resolution for: https://github.com/diffplug/spotless/issues/243#issuecomment-564323856
48-
// project.getRootProject() is consistent across every project, so only of one the clears will
49-
// actually happen (as desired)
50-
//
51-
// we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
52-
SpotlessCache.clearOnce(System.identityHashCode(project.getRootProject()));
53-
});
54-
});
45+
// resolution for: https://github.com/diffplug/spotless/issues/243#issuecomment-564323856
46+
// project.getRootProject() is consistent across every project, so only of one the clears will
47+
// actually happen (as desired)
48+
//
49+
// we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
50+
int cacheKey = System.identityHashCode(project.getRootProject());
51+
project.getTasks().named(BasePlugin.CLEAN_TASK_NAME).configure(clean -> clean.doLast(unused -> SpotlessCache.clearOnce(cacheKey)));
5552
}
5653

5754
static String capitalize(String input) {

0 commit comments

Comments
 (0)