diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e8a1a800d2..c02773cc52 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -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 diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java index c62dd03418..80025f3164 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java @@ -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. @@ -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) {