Skip to content

Commit

Permalink
Centralize gradle versions so we can remove version-specific workarou…
Browse files Browse the repository at this point in the history
…nds as soon as possible.
  • Loading branch information
nedtwigg authored and Goooler committed Apr 4, 2023
1 parent 4410531 commit 1c21d12
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface JvmLang {
default FileCollection getSources(Project project, String message, Function<SourceSet, SourceDirectorySet> sourceSetSourceDirectory, Spec<? super File> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

public class SpotlessPlugin implements Plugin<Project> {
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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c21d12

Please sign in to comment.