Skip to content

Commit

Permalink
Fix the Gradle plugin not to break the clean task when Gradle's con…
Browse files Browse the repository at this point in the history
…figuration cache is enabled (#797)
  • Loading branch information
nedtwigg authored Feb 11, 2021
2 parents 95b7c5c + f92fbb8 commit a5c44dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

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

## [5.10.0] - 2021-02-09
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,16 +42,13 @@ public void apply(Project project) {
project.getExtensions().create(SpotlessExtension.class, SpotlessExtension.EXTENSION, SpotlessExtensionImpl.class, project);

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

static String capitalize(String input) {
Expand Down

0 comments on commit a5c44dd

Please sign in to comment.