Skip to content

Commit

Permalink
The maven and gradle plugins yell at their users to update to Java 11…
Browse files Browse the repository at this point in the history
…, and how to update without affecting their users.
  • Loading branch information
nedtwigg committed Jan 24, 2023
1 parent 1c5a3ef commit 14e71fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 14e71fb

Please sign in to comment.