From 1c21d12ebc7e1dabdb6d2001df18fff8d84c1fe4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 27 Mar 2023 18:37:25 -0700 Subject: [PATCH] Centralize gradle versions so we can remove version-specific workarounds as soon as possible. --- .../src/main/java/com/diffplug/gradle/spotless/JvmLang.java | 2 +- .../java/com/diffplug/gradle/spotless/SpotlessPlugin.java | 5 +++-- .../diffplug/gradle/spotless/SpotlessPluginRedirect.java | 6 +++--- .../diffplug/gradle/spotless/GradleIntegrationHarness.java | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java index 6e30674c6c..1a9a06b986 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java @@ -34,7 +34,7 @@ interface JvmLang { default FileCollection getSources(Project project, String message, Function sourceSetSourceDirectory, Spec filterSpec) { final SourceSetContainer sourceSets; FileCollection union = project.files(); - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + if (GradleVersion.current().compareTo(GradleVersion.version(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) { final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class); if (javaPluginExtension == null) { throw new GradleException(message); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java index 91847af0cf..0043e2b274 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java @@ -26,13 +26,14 @@ public class SpotlessPlugin implements Plugin { static final String SPOTLESS_MODERN = "spotlessModern"; - static final String MINIMUM_GRADLE = "6.1.1"; + static final String VER_GRADLE_min = "6.1.1"; + static final String VER_GRADLE_javaPluginExtension = "7.1"; private static final int MINIMUM_JRE = 11; @Override public void apply(Project project) { if (SpotlessPluginRedirect.gradleIsTooOld(project)) { - throw new GradleException("Spotless requires Gradle " + MINIMUM_GRADLE + " or newer, this was " + project.getGradle().getGradleVersion()); + throw new GradleException("Spotless requires Gradle " + VER_GRADLE_min + " or newer, this was " + project.getGradle().getGradleVersion()); } if (Jvm.version() < MINIMUM_JRE) { throw new GradleException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + JavaVersion.current() + ".\n" diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java index da4d3dcd8b..975ec5576e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ private static int badSemver(int major, int minor) { static boolean gradleIsTooOld(Project project) { if (gradleIsTooOld == null) { - gradleIsTooOld = badSemver(project.getGradle().getGradleVersion()) < badSemver(SpotlessPlugin.MINIMUM_GRADLE); + gradleIsTooOld = badSemver(project.getGradle().getGradleVersion()) < badSemver(SpotlessPlugin.VER_GRADLE_min); } return gradleIsTooOld.booleanValue(); } @@ -73,7 +73,7 @@ public void apply(Project project) { "If you like the idea behind 'ratchetFrom', you should checkout spotless-changelog", "https://github.com/diffplug/spotless-changelog"); if (gradleIsTooOld(project)) { - errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade gradle to " + SpotlessPlugin.MINIMUM_GRADLE + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); + errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade gradle to " + SpotlessPlugin.VER_GRADLE_min + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); } throw new GradleException(errorMsg); } 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 1763fd088f..61d191bab1 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 @@ -43,7 +43,7 @@ public class GradleIntegrationHarness extends ResourceHarness { public enum GradleVersionSupport { - JRE_11("5.0"), MINIMUM(SpotlessPlugin.MINIMUM_GRADLE), + JRE_11("5.0"), MINIMUM(SpotlessPlugin.VER_GRADLE_min), // technically, this API exists in 6.5, but the flags for it change in 6.6, so we build to that CONFIGURATION_CACHE("6.6"), // https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:stable