Skip to content

Bump the min Gradle and Java requirements to 7.3 and 17 #2540

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/changelog-print.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ jobs:
name: changelogPrint
steps:
- uses: actions/checkout@v4
- name: jdk 11
uses: actions/setup-java@v4
- uses: actions/setup-java@v4
with:
java-version: 11
java-version: 21
distribution: 'temurin'
- name: gradle caching
uses: gradle/actions/setup-gradle@v4
Expand Down
25 changes: 8 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install JDK 11
uses: actions/setup-java@v4
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 11
java-version: 21
- name: gradle caching
uses: gradle/actions/setup-gradle@v4
- name: spotlessCheck
Expand All @@ -41,33 +40,25 @@ jobs:
matrix:
kind: [maven, gradle]
# Test on the latest Java version once Gradle & Maven support it.
jre: [11, 17, 21, 24]
os: [ubuntu-latest]
jre: [17, 21, 24]
os: [ubuntu-latest, windows-latest]
include:
# test windows at the diagonals of the above matrix
- kind: maven
jre: 11
os: windows-latest
- kind: gradle
jre: 17
os: windows-latest
# npm on linux only (crazy slow on windows)
- kind: npm
jre: 11
jre: 17
os: ubuntu-latest
- kind: shfmt
jre: 11
jre: 17
os: ubuntu-latest
shfmt-version: v3.8.0
- kind: idea
jre: 11
jre: 17
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }}
uses: actions/setup-java@v4
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ matrix.jre }}
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ jobs:
ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }}
steps:
- uses: actions/checkout@v4
- name: jdk 11
uses: actions/setup-java@v4
- uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'
- name: gradle caching
uses: gradle/actions/setup-gradle@v4
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true

name=spotless
description=Spotless - keep your code spotless with Gradle
Expand Down Expand Up @@ -32,4 +33,4 @@ VER_JGIT=6.10.1.202505221210-r
VER_JUNIT=5.13.3
VER_ASSERTJ=3.27.3
VER_MOCKITO=5.18.0
VER_SELFIE=2.5.3
VER_SELFIE=2.5.3
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-rc-1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/
package com.diffplug.spotless.extra.cpp;

import static org.junit.jupiter.api.condition.JRE.JAVA_17;

import java.util.stream.Stream;

import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand All @@ -33,7 +30,6 @@ public EclipseCdtFormatterStepTest() {

@ParameterizedTest
@MethodSource
@EnabledForJreRange(min = JAVA_17)
void formatWithVersion(String version) throws Exception {
harnessFor(version).test("main.c",
"#include <a.h>;\nint main(int argc, \nchar *argv[]) {}",
Expand Down
7 changes: 7 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.util.GradleVersion

plugins {
id 'java-library'
id 'io.github.davidburstrom.version-compatibility'
Expand Down Expand Up @@ -148,6 +150,11 @@ tasks.withType(Test).configureEach {
// https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers
jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED"
}

if (GradleVersion.current() >= GradleVersion.version('9.0')) {
// https://github.com/gradle/gradle/issues/33619
failOnNoDiscoveredTests = false
}
}

jar {
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]

## Changed
* Bump the min Gradle and Java requirements to `7.3` and `17`. ([#2540](https://github.com/diffplug/spotless/pull/2540))
* Bump default `gson` version to latest `2.11.0` -> `2.13.1`. ([#2414](https://github.com/diffplug/spotless/pull/2414))
* Bump default `jackson` version to latest `2.18.1` -> `2.19.1`. ([#2352](https://github.com/diffplug/spotless/pull/2352))
* Bump default `gherkin-utils` version to latest `9.0.0` -> `9.2.0`. ([#2408](https://github.com/diffplug/spotless/pull/2408))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2025 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 @@ -18,11 +18,8 @@
import javax.inject.Inject;

import org.gradle.api.GradleException;
import org.gradle.api.internal.plugins.DslObject;
import org.gradle.api.plugins.GroovyBasePlugin;
import org.gradle.api.tasks.GroovySourceDirectorySet;
import org.gradle.api.tasks.GroovySourceSet;
import org.gradle.util.GradleVersion;

import com.diffplug.spotless.generic.LicenseHeaderStep;

Expand Down Expand Up @@ -66,12 +63,7 @@ protected void setupTask(SpotlessTask task) {
target = getSources(getProject(),
message,
sourceSet -> {
if (GradleVersion.current().compareTo(GradleVersion.version(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) {
return sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
} else {
final GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
return groovySourceSet.getGroovy();
}
return sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
},
file -> {
final String name = file.getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2025 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 @@ -22,31 +22,20 @@
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.util.GradleVersion;

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(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) {
final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
if (javaPluginExtension == null) {
throw new GradleException(message);
}
sourceSets = javaPluginExtension.getSourceSets();
} else {
final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
if (javaPluginConvention == null) {
throw new GradleException(message);
}
sourceSets = javaPluginConvention.getSourceSets();
final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
if (javaPluginExtension == null) {
throw new GradleException(message);
}
final SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
for (SourceSet sourceSet : sourceSets) {
union = union.plus(sourceSetSourceDirectory.apply(sourceSet).filter(filterSpec));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@

public class SpotlessPlugin implements Plugin<Project> {
static final String SPOTLESS_MODERN = "spotlessModern";
static final String VER_GRADLE_min = "6.1.1";
static final String VER_GRADLE_javaPluginExtension = "7.1";
static final String VER_GRADLE_min = "7.3";
static final String VER_GRADLE_minVersionForCustom = "8.4";
private static final int MINIMUM_JRE = 11;
private static final int MINIMUM_JRE = 17;

@Override
public void apply(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@

public class GradleIntegrationHarness extends ResourceHarness {
public enum GradleVersionSupport {
JRE_11("5.0"), MINIMUM(SpotlessPlugin.VER_GRADLE_min), CUSTOM_STEPS(SpotlessPlugin.VER_GRADLE_minVersionForCustom),
// 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"),
MINIMUM(SpotlessPlugin.VER_GRADLE_min),

// https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:stable
STABLE_CONFIGURATION_CACHE("7.5");
STABLE_CONFIGURATION_CACHE("7.5"),

CUSTOM_STEPS(SpotlessPlugin.VER_GRADLE_minVersionForCustom),

;

final String version;

Expand Down Expand Up @@ -77,18 +80,6 @@ public enum GradleVersionSupport {
case 18:
minVersionForRunningJRE = "7.5";
break;
case 17:
minVersionForRunningJRE = "7.3";
break;
case 16:
minVersionForRunningJRE = "7.0";
break;
case 15:
minVersionForRunningJRE = "6.7";
break;
case 14:
minVersionForRunningJRE = "6.3";
break;
default:
minVersionForRunningJRE = null;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NativeCmdWithConfigCacheTest extends GradleIntegrationHarness implements N
public GradleRunner gradleRunner() throws IOException {
setFile("gradle.properties").toLines("org.gradle.unsafe.configuration-cache=true",
"org.gradle.configuration-cache=true");
return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version);
return super.gradleRunner();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 DiffPlug
* Copyright 2020-2025 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 @@ -15,13 +15,10 @@
*/
package com.diffplug.gradle.spotless;

import static org.junit.jupiter.api.condition.JRE.JAVA_11;

import java.io.IOException;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;

import com.diffplug.common.base.StringPrinter;

Expand All @@ -39,35 +36,4 @@ void redirectPluginModernGradle() throws IOException {
" To migrate:",
" - Test your build with: id 'com.diffplug.gradle.spotless' version '4.5.1'"));
}

@Test
@EnabledForJreRange(max = JAVA_11)
void redirectPluginOldGradle() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}");
Assertions.assertThat(gradleRunner().withGradleVersion(GradleVersionSupport.JRE_11.version)
.buildAndFail().getOutput().replace("\r", ""))
.contains(StringPrinter.buildStringFromLines(
"> Failed to apply plugin [id 'com.diffplug.gradle.spotless']",
" > We have moved from 'com.diffplug.gradle.spotless'",
" to 'com.diffplug.spotless'",
" To migrate:",
" - Upgrade Gradle to 6.1.1 or newer (you're on 5.0)",
" - Test your build with: id 'com.diffplug.gradle.spotless' version '4.5.1'"));
}

@Test
@EnabledForJreRange(max = JAVA_11)
void realPluginOldGradle() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
"}");
Assertions.assertThat(gradleRunner().withGradleVersion(GradleVersionSupport.JRE_11.version)
.buildAndFail().getOutput().replace("\r", ""))
.contains(StringPrinter.buildStringFromLines(
"Spotless requires Gradle 6.1.1 or newer, this was 5.0"));
}
}
2 changes: 1 addition & 1 deletion testlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply from: rootProject.file('gradle/java-setup.gradle')

dependencies {
api projects.lib
api files(projects.lib.dependencyProject.sourceSets.sortPom.output.classesDirs)
api files(project(projects.lib.path).sourceSets.sortPom.output.classesDirs)
api "com.diffplug.durian:durian-core:${VER_DURIAN}"
api "com.diffplug.durian:durian-testlib:${VER_DURIAN}"
api "org.junit.jupiter:junit-jupiter:${VER_JUNIT}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 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 @@ -82,7 +82,7 @@ private static Provisioner createWithRepositories(Consumer<RepositoryHandler> re
return config.resolve();
} catch (ResolveException e) {
/* Provide Maven coordinates in exception message instead of static string 'detachedConfiguration' */
throw new ResolveException(config.getDescription(), e);
throw new RuntimeException("Error resolving configuration: " + config.getDescription(), e);
} finally {
// delete the temp dir
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 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 @@ -15,7 +15,6 @@
*/
package com.diffplug.spotless.java;

import static org.junit.jupiter.api.condition.JRE.JAVA_13;
import static org.junit.jupiter.api.condition.JRE.JAVA_15;
import static org.junit.jupiter.api.condition.JRE.JAVA_20;
import static org.junit.jupiter.api.condition.JRE.JAVA_21;
Expand All @@ -33,7 +32,6 @@
class GoogleJavaFormatStepTest extends ResourceHarness {

@Test
@EnabledForJreRange(min = JAVA_13)
void jvm13Features() throws Exception {
try (StepHarness step = StepHarness.forStep(GoogleJavaFormatStep.create(TestProvisioner.mavenCentral()))) {
step.testResource("java/googlejavaformat/TextBlock.dirty", "java/googlejavaformat/TextBlock.clean");
Expand Down
Loading
Loading