Skip to content

Commit

Permalink
Add a test for configuring a single plugin-gradle block multiple times (
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Sep 21, 2020
2 parents edc8a99 + 4834fe4 commit 3d6b680
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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
* `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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public <T extends FormatExtension> void format(String name, Class<T> clazz, Acti
protected final <T extends FormatExtension> T maybeCreate(String name, Class<T> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 3d6b680

Please sign in to comment.