Skip to content

Commit 3d6b680

Browse files
authored
Add a test for configuring a single plugin-gradle block multiple times (#702)
2 parents edc8a99 + 4834fe4 commit 3d6b680

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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+
* `5.6.0` introduced a bug where it was no longer possible to configure a single format twice, e.g. to have two `java{}` blocks in a single file. Fixed by [#702](https://github.com/diffplug/spotless/pull/702).
68

79
## [5.6.0] - 2020-09-21
810
### Added

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public <T extends FormatExtension> void format(String name, Class<T> clazz, Acti
211211
protected final <T extends FormatExtension> T maybeCreate(String name, Class<T> clazz) {
212212
FormatExtension existing = formats.get(name);
213213
if (existing != null) {
214-
if (!existing.getClass().equals(clazz)) {
214+
if (!clazz.isInstance(existing)) {
215215
throw new GradleException("Tried to add format named '" + name + "'" +
216216
" of type " + clazz + " but one has already been created of type " + existing.getClass());
217217
} else {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ public void integration() throws IOException {
4545
assertFile("src/main/groovy/test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
4646
assertFile("src/main/groovy/test.groovy").sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
4747
}
48+
49+
@Test
50+
public void multipleBlocksShouldWork() throws IOException {
51+
setFile("build.gradle").toLines(
52+
"buildscript { repositories { mavenCentral() } }",
53+
"plugins {",
54+
" id 'com.diffplug.spotless'",
55+
" id 'java'",
56+
"}",
57+
"",
58+
"spotless {",
59+
" java { googleJavaFormat() }",
60+
" java { eclipse() }",
61+
"}");
62+
gradleRunner().withArguments("spotlessApply").build();
63+
gradleRunner().withArguments("spotlessApply").build();
64+
}
4865
}

0 commit comments

Comments
 (0)