diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e436abd95..d11b0b1166 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,8 @@ jobs: fail-fast: false matrix: kind: [maven, gradle] - jre: [11, 17] + # Test on the latest Java version once Gradle & Maven support it. + jre: [11, 17, 21] os: [ubuntu-latest] include: # test windows at the diagonals of the above matrix diff --git a/CHANGES.md b/CHANGES.md index d5443669a0..c1e3d9d101 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [2.43.0] - 2023-11-27 ### Added diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c49..d64cd49177 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f862f7..1af9e0930b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/lib/build.gradle b/lib/build.gradle index 6dcb888e73..2963036b2e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -84,7 +84,7 @@ dependencies { gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2' gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0' // googleJavaFormat - googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.17.0' + googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.18.1' // gson gsonCompileOnly 'com.google.code.gson:gson:2.10.1' // jackson diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index e5d990d807..6a48924170 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -35,7 +35,7 @@ private GoogleJavaFormatStep() {} private static final boolean DEFAULT_REORDER_IMPORTS = false; private static final boolean DEFAULT_FORMAT_JAVADOC = true; static final String NAME = "google-java-format"; - static final String MAVEN_COORDINATE = "com.google.googlejavaformat:google-java-format"; + public static final String MAVEN_COORDINATE = "com.google.googlejavaformat:google-java-format"; /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(Provisioner provisioner) { @@ -83,7 +83,7 @@ public static FormatterStep create(String groupArtifact, String version, String .addMin(11, "1.8") // we only support google-java-format >= 1.8 due to api changes .addMin(16, "1.10.0") // java 16 requires at least 1.10.0 due to jdk api changes in JavaTokenizer .addMin(21, "1.17.0") // java 21 requires at least 1.17.0 due to https://github.com/google/google-java-format/issues/898 - .add(11, "1.17.0"); // default version + .add(11, "1.18.1"); // default version public static String defaultGroupArtifact() { return MAVEN_COORDINATE; diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index f769ad09ec..8cb828c624 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -29,8 +29,8 @@ private PalantirJavaFormatStep() {} private static final String DEFAULT_STYLE = "PALANTIR"; private static final String NAME = "palantir-java-format"; - private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0"); + public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.38.0"); /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(Provisioner provisioner) { diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d00ba16d37..5fd3e2ae8b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changes +* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ### Fixed * Make `KtfmtConfig.ConfigurableStyle#configure` public. ([#1926](https://github.com/diffplug/spotless/pull/1926)) * **BREAKING CHANGE** `6.23.0` made breaking changes to the ABI of the `KotlinExtension` and `GroovyExtension`. Those are reflected retroactively now. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 288cc10c72..6bb8c1b50e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -26,6 +26,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.dsl.DependencyHandler; +import org.gradle.api.attributes.Attribute; import org.gradle.api.attributes.Bundling; import org.gradle.api.attributes.Category; import org.gradle.api.initialization.dsl.ScriptHandler; @@ -35,6 +36,8 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.java.GoogleJavaFormatStep; +import com.diffplug.spotless.java.PalantirJavaFormatStep; /** Should be package-private. */ class GradleProvisioner { @@ -116,7 +119,16 @@ private static Provisioner forConfigurationContainer(Project project, Configurat + new Request(withTransitives, mavenCoords).hashCode()); mavenCoords.stream() .map(dependencies::create) - .forEach(config.getDependencies()::add); + .forEach(dependency -> { + config.getDependencies().add(dependency); + String coordinate = dependency.getGroup() + ":" + dependency.getName(); + if (coordinate.startsWith(GoogleJavaFormatStep.MAVEN_COORDINATE) || + coordinate.startsWith(PalantirJavaFormatStep.MAVEN_COORDINATE)) { + // Use Guava 32.1.3, see https://github.com/google/guava/issues/6657. + // TODO: May remove this after https://github.com/google/google-java-format/pull/996 and https://github.com/palantir/palantir-java-format/issues/957 are released. + config.getDependencies().add(dependencies.create("com.google.guava:guava:32.1.3-jre")); + } + }); config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); config.setCanBeConsumed(false); @@ -124,6 +136,9 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.attributes(attr -> { attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + // TODO: This is a copy-paste from org.gradle.api.attributes.java.TargetJvmEnvironment which is added in Gradle 7.0, remove this once we drop support for Gradle 6.x. + // Add this attribute for resolving Guava dependency, see https://github.com/google/guava/issues/6801. + attr.attribute(Attribute.of("org.gradle.jvm.environment", String.class), "standard-jvm"); }); return config.resolve(); } catch (Exception e) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java index 396a884cc5..70be5adb82 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java @@ -20,6 +20,8 @@ import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; public class ConfigurationCacheTest extends GradleIntegrationHarness { @Override @@ -63,6 +65,7 @@ public void helpConfiguresIfTasksAreCreated() throws IOException { } @Test + @EnabledForJreRange(max = JRE.JAVA_20) public void jvmLocalCache() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -91,6 +94,10 @@ public void jvmLocalCache() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test"); + // the withDebug forces it to start a new deamon, but only in Gradle 8.3 and older + // starting with Gradle 8.5 this doesn't work anymore + // and we need Gradle 8.5 for Java 21 + // so we can't test this on Java 21 for now BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail(); failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" + " rm -rf .gradle/configuration-cache\n" + diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java index b2ee012091..e7fc9d4b74 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.10.0')", + " googleJavaFormat('1.17.0')", " }", "}"); @@ -41,7 +41,7 @@ void integration() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.10.0')", + "googleJavaFormat('1.17.0')", "googleJavaFormat()"); checkRunsThenUpToDate(); } @@ -57,7 +57,7 @@ void integrationWithReorderImports() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.12.0').aosp().reorderImports(true)", + " googleJavaFormat('1.17.0').aosp().reorderImports(true)", " }", "}"); @@ -67,7 +67,7 @@ void integrationWithReorderImports() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.12.0')", + "googleJavaFormat('1.17.0')", "googleJavaFormat()"); checkRunsThenUpToDate(); } @@ -83,7 +83,7 @@ void integrationWithSkipJavadocFormatting() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.12.0').skipJavadocFormatting()", + " googleJavaFormat('1.17.0').skipJavadocFormatting()", " }", "}"); @@ -93,7 +93,7 @@ void integrationWithSkipJavadocFormatting() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.12.0')", + "googleJavaFormat('1.17.0')", "googleJavaFormat()"); checkRunsThenUpToDate(); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index ade5cf3d1d..9e1856b6b0 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -54,9 +54,14 @@ public enum GradleVersionSupport { GradleVersionSupport(String version) { String minVersionForRunningJRE; switch (Jvm.version()) { + case 22: + // TODO: https://docs.gradle.org/current/userguide/compatibility.html case 21: + minVersionForRunningJRE = "8.5"; + break; case 20: - // TODO: https://docs.gradle.org/current/userguide/compatibility.html + minVersionForRunningJRE = "8.3"; + break; case 19: minVersionForRunningJRE = "7.6"; break; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java index 98761b472a..5d184e15e5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java @@ -47,7 +47,7 @@ void createSubproject(String name) throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.16.0')", + " googleJavaFormat('1.17.0')", " }", "}"); setFile(name + "/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -71,7 +71,7 @@ public void hasRootSpotless() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.16.0')", + " googleJavaFormat('1.17.0')", " }", "}"); setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -88,7 +88,7 @@ public void predeclaredFails() throws IOException { "spotless { predeclareDeps() }"); createNSubprojects(); Assertions.assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()) - .contains("Add a step with [com.google.googlejavaformat:google-java-format:1.16.0] into the `spotlessPredeclare` block in the root project."); + .contains("Add a step with [com.google.googlejavaformat:google-java-format:1.17.0] into the `spotlessPredeclare` block in the root project."); } @Test @@ -100,7 +100,7 @@ public void predeclaredSucceeds() throws IOException { "repositories { mavenCentral() }", "spotless { predeclareDeps() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}"); createNSubprojects(); gradleRunner().withArguments("spotlessApply").build(); @@ -115,7 +115,7 @@ public void predeclaredFromBuildscriptSucceeds() throws IOException { "repositories { mavenCentral() }", "spotless { predeclareDepsFromBuildscript() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}"); createNSubprojects(); gradleRunner().withArguments("spotlessApply").build(); @@ -129,7 +129,7 @@ public void predeclaredOrdering() throws IOException { "}", "repositories { mavenCentral() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}", "spotless { predeclareDepsFromBuildscript() }"); createNSubprojects(); @@ -145,7 +145,7 @@ public void predeclaredUndeclared() throws IOException { "}", "repositories { mavenCentral() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}"); createNSubprojects(); Assertions.assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 590e57a196..2880df029b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,12 +3,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ### Fixed * Revert [#1846](https://github.com/diffplug/spotless/issues/1846) from 2.41.0 which causes the plugin to format generated sources in the `target` directory. ([#1928](https://github.com/diffplug/spotless/pull/1928)) ## [2.41.0] - 2023-11-27 ### Added -* CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) +* ~~CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories.~~ ([#1846](https://github.com/diffplug/spotless/issues/1846)) + * Reverted in the next release (`2.41.1`) due to backward compatibility problems, see [#1914](https://github.com/diffplug/spotless/issues/1914). * Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896)) ### Fixed * Fix crash when build dir is a softlink to another directory. ([#1859](https://github.com/diffplug/spotless/pull/1859)) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java index 5af146c736..e1214a0d59 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java @@ -33,7 +33,6 @@ void testMultipleDependenciesExcludingTransitives() throws Exception { void testSingleDependencyIncludingTransitives() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", ""); assertResolveDependenciesWorks(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java index 11cca5994a..6ce11d179f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java @@ -58,7 +58,6 @@ private void integration(String patterns, boolean firstFormatted, boolean second " src/**/java/**/*.java", "", "", - " 1.10.0", ""); setFile(testFile(1)).toResource(fixture(false)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 40d8edfed2..52e89e58db 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -24,7 +24,7 @@ class GoogleJavaFormatTest extends MavenIntegrationHarness { void specificVersionDefaultStyle() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", + " 1.17.0", ""); runTest("java/googlejavaformat/JavaCodeFormatted.test"); @@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception { void specificVersionSpecificStyle() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", + " 1.17.0", " ", ""); @@ -45,7 +45,7 @@ void specificVersionSpecificStyle() throws Exception { void specificVersionReflowLongStrings() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", + " 1.17.0", " true", ""); @@ -56,7 +56,7 @@ void specificVersionReflowLongStrings() throws Exception { void specificVersionReorderImports() throws Exception { writePomWithJavaSteps( "", - " 1.12.0", + " 1.17.0", " ", " true", ""); @@ -68,7 +68,7 @@ void specificVersionReorderImports() throws Exception { void specificVersionSkipJavadocFormatting() throws Exception { writePomWithJavaSteps( "", - " 1.12.0", + " 1.17.0", " false", ""); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java index d8d66fa46d..6a3fd8b08b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java @@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception { void specificJava11Version2() throws Exception { writePomWithJavaSteps( "", - " 2.10.0", + " 2.38.0", ""); runTest("java/palantirjavaformat/JavaCodeFormatted.test"); diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 7c7b7b67f7..53a5cfed30 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -25,12 +25,14 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.stream.Stream; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.ResolveException; import org.gradle.api.artifacts.dsl.RepositoryHandler; +import org.gradle.api.attributes.Attribute; import org.gradle.api.attributes.Bundling; import org.gradle.api.attributes.Category; import org.gradle.testfixtures.ProjectBuilder; @@ -40,6 +42,8 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; +import com.diffplug.spotless.java.GoogleJavaFormatStep; +import com.diffplug.spotless.java.PalantirJavaFormatStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -64,7 +68,15 @@ private static Provisioner createWithRepositories(Consumer re Project project = TestProvisioner.gradleProject(tempDir); repoConfig.accept(project.getRepositories()); return (withTransitives, mavenCoords) -> { - Dependency[] deps = mavenCoords.stream() + boolean forceGuava = mavenCoords.stream().anyMatch(coordinate -> coordinate.startsWith(GoogleJavaFormatStep.MAVEN_COORDINATE) || + coordinate.startsWith(PalantirJavaFormatStep.MAVEN_COORDINATE)); + Stream coordinateStream = mavenCoords.stream(); + if (forceGuava) { + // Use Guava 32.1.3, see https://github.com/google/guava/issues/6657. + // TODO: May remove this after https://github.com/google/google-java-format/pull/996 and https://github.com/palantir/palantir-java-format/issues/957 are released. + coordinateStream = Stream.concat(coordinateStream, Stream.of("com.google.guava:guava:32.1.3-jre")); + } + Dependency[] deps = coordinateStream .map(project.getDependencies()::create) .toArray(Dependency[]::new); Configuration config = project.getConfigurations().detachedConfiguration(deps); @@ -73,6 +85,9 @@ private static Provisioner createWithRepositories(Consumer re config.attributes(attr -> { attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + // TODO: This is a copy-paste from org.gradle.api.attributes.java.TargetJvmEnvironment which is added in Gradle 7.0, remove this once we drop support for Gradle 6.x. + // Add this attribute for resolving Guava dependency, see https://github.com/google/guava/issues/6801. + attr.attribute(Attribute.of("org.gradle.jvm.environment", String.class), "standard-jvm"); }); try { return config.resolve(); diff --git a/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java index cc32281771..d1eb023400 100644 --- a/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java @@ -34,7 +34,7 @@ public class CombinedJavaFormatStepTest extends ResourceHarness { @Test void checkIssue1679() { - FormatterStep gjf = GoogleJavaFormatStep.create("1.15.0", "AOSP", mavenCentral()); + FormatterStep gjf = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), "AOSP", mavenCentral()); FormatterStep indentWithSpaces = IndentStep.Type.SPACE.create(); FormatterStep importOrder = ImportOrderStep.forJava().createFrom(); FormatterStep removeUnused = RemoveUnusedImportsStep.create(mavenCentral()); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index f8766d7c6f..c2ec5b5d7f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.condition.JRE.JAVA_13; import static org.junit.jupiter.api.condition.JRE.JAVA_15; import static org.junit.jupiter.api.condition.JRE.JAVA_16; +import static org.junit.jupiter.api.condition.JRE.JAVA_20; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; @@ -52,7 +53,7 @@ void behavior18() throws Exception { @Test void behavior() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create("1.10.0", TestProvisioner.mavenCentral()); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test") @@ -79,7 +80,7 @@ void versionBelowOneDotTenIsNotAllowed() throws Exception { @Test void behaviorWithAospStyle() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create("1.10.0", "AOSP", TestProvisioner.mavenCentral()); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), "AOSP", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormattedAOSP.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormattedAOSP.test") @@ -111,7 +112,7 @@ void behaviorWithSkipFormatJavadoc() throws Exception { @Test void behaviorWithCustomGroupArtifact() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.10.0", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), GoogleJavaFormatStep.defaultVersion(), GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test") @@ -133,6 +134,7 @@ void behaviorWithReorderImports() throws Exception { } @Test + @EnabledForJreRange(max = JAVA_20) void equality() throws Exception { new SerializableEqualityTester() { String version = "1.10.0"; @@ -163,6 +165,7 @@ protected FormatterStep create() { } @Test + @EnabledForJreRange(max = JAVA_20) void equalityGroupArtifact() throws Exception { new SerializableEqualityTester() { String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact(); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index 81d03b6c32..7cd1aad438 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -38,7 +38,7 @@ void jvm13Features() throws Exception { @Test void behavior2() throws Exception { - FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); + FormatterStep step = PalantirJavaFormatStep.create(TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/palantirjavaformat/JavaCodeUnformatted.test", "java/palantirjavaformat/JavaCodeFormatted.test") .testResource("java/palantirjavaformat/JavaCodeWithLicenseUnformatted.test", "java/palantirjavaformat/JavaCodeWithLicenseFormatted.test")