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 0911c1d48d..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) { 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 2c3b84c40d..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,7 +29,7 @@ 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:"; + 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. */ 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 9003445ddd..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 @@ -36,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 { @@ -117,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); diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 04c4476804..53a5cfed30 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -25,6 +25,7 @@ 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; @@ -41,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) { @@ -65,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);