17
17
18
18
import org .gradle .api .Plugin ;
19
19
import org .gradle .api .Project ;
20
- import org .gradle .api .Task ;
21
20
import org .gradle .api .plugins .BasePlugin ;
22
21
23
22
import com .diffplug .spotless .SpotlessCache ;
@@ -35,14 +34,15 @@ public void apply(Project project) {
35
34
project .getExtensions ().create (SpotlessExtension .EXTENSION , SpotlessExtensionModern .class , project );
36
35
37
36
// clear spotless' cache when the user does a clean
38
- Task clean = project .getTasks ().getByName (BasePlugin .CLEAN_TASK_NAME );
39
- clean .doLast (unused -> {
40
- // resolution for: https://github.com/diffplug/spotless/issues/243#issuecomment-564323856
41
- // project.getRootProject() is consistent across every project, so only of one the clears will
42
- // actually happen (as desired)
43
- //
44
- // we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
45
- SpotlessCache .clearOnce (System .identityHashCode (project .getRootProject ()));
37
+ project .getTasks ().named (BasePlugin .CLEAN_TASK_NAME ).configure (clean -> {
38
+ clean .doLast (unused -> {
39
+ // resolution for: https://github.com/diffplug/spotless/issues/243#issuecomment-564323856
40
+ // project.getRootProject() is consistent across every project, so only of one the clears will
41
+ // actually happen (as desired)
42
+ //
43
+ // we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
44
+ SpotlessCache .clearOnce (System .identityHashCode (project .getRootProject ()));
45
+ });
46
46
});
47
47
}
48
48
}
0 commit comments