Skip to content

Bump minimum JRE to 11 (gracefully) #1514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 26, 2023
Merged
Prev Previous commit
Next Next commit
The maven and gradle plugins yell at their users to update to Java 11…
…, and how to update without affecting their users.
  • Loading branch information
nedtwigg committed Jan 24, 2023
commit 14e71fb57d313726b0b11f9ece946001540d55cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 DiffPlug
* Copyright 2016-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 All @@ -16,21 +16,29 @@
package com.diffplug.gradle.spotless;

import org.gradle.api.GradleException;
import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.BasePlugin;

import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.SpotlessCache;

public class SpotlessPlugin implements Plugin<Project> {
static final String SPOTLESS_MODERN = "spotlessModern";
static final String MINIMUM_GRADLE = "6.1.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());
}
if (Jvm.version() < MINIMUM_JRE) {
throw new GradleException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + JavaVersion.current() + ".\n"
+ "You can upgrade your build JRE and still compile for older targets, see below\n"
+ "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation");
}
// if -PspotlessModern=true, then use the modern stuff instead of the legacy stuff
if (project.hasProperty(SPOTLESS_MODERN)) {
project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.sonatype.plexus.build.incremental.BuildContext;

import com.diffplug.spotless.Formatter;
import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.LineEnding;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.generic.LicenseHeaderStep;
Expand Down Expand Up @@ -190,6 +191,16 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {

protected abstract void process(Iterable<File> files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException;

private static final int MINIMUM_JRE = 11;

protected AbstractSpotlessMojo() {
if (Jvm.version() < MINIMUM_JRE) {
throw new RuntimeException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + Jvm.version() + ".\n"
+ "You can upgrade your build JRE and still compile for older targets, see below\n"
+ "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation");
}
}

@Override
public final void execute() throws MojoExecutionException {
if (shouldSkip()) {
Expand Down