From 13560e949cae55cec28f1953c1c88ab029990581 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 21 Sep 2020 13:44:32 -0700 Subject: [PATCH 1/3] Add a test for configuring a single thing multiple times. --- .../gradle/spotless/JavaDefaultTargetTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java index 8fb53e1633..b2f004cb3d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java @@ -45,4 +45,21 @@ public void integration() throws IOException { assertFile("src/main/groovy/test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test"); assertFile("src/main/groovy/test.groovy").sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test"); } + + @Test + public void multipleBlocksShouldWork() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'com.diffplug.spotless'", + " id 'java'", + "}", + "", + "spotless {", + " java { googleJavaFormat() }", + " java { eclipse() }", + "}"); + gradleRunner().withArguments("spotlessApply").build(); + gradleRunner().withArguments("spotlessApply").build(); + } } From 7381efabb03c58c97f297899d80b803e1842adb0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 21 Sep 2020 13:07:47 -0700 Subject: [PATCH 2/3] Fix reconfiguring existing formats. --- .../java/com/diffplug/gradle/spotless/SpotlessExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 2530ef2205..1f55efc1ee 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -211,7 +211,7 @@ public void format(String name, Class clazz, Acti protected final T maybeCreate(String name, Class clazz) { FormatExtension existing = formats.get(name); if (existing != null) { - if (!existing.getClass().equals(clazz)) { + if (!clazz.isInstance(existing)) { throw new GradleException("Tried to add format named '" + name + "'" + " of type " + clazz + " but one has already been created of type " + existing.getClass()); } else { From 4834fe413cab86f7d6fe65062896037507e426f7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 21 Sep 2020 13:51:21 -0700 Subject: [PATCH 3/3] Update changelog. --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c0d85d96bc..c316870fd9 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 +* `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). ## [5.6.0] - 2020-09-21 ### Added