diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86cf955059..8901a164d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,19 +40,19 @@ jobs: fail-fast: false matrix: kind: [maven, gradle] - jre: [8, 11, 17] + jre: [11, 17] os: [ubuntu-latest] include: # test windows at the diagonals of the above matrix - kind: maven - jre: 8 + jre: 11 os: windows-latest - kind: gradle jre: 17 os: windows-latest # npm on linux only (crazy slow on windows) - kind: npm - jre: 8 + jre: 11 os: ubuntu-latest runs-on: ${{ matrix.os }} steps: diff --git a/CHANGES.md b/CHANGES.md index d41f40aaa6..efbf1e5ae0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11, next release likely to bump bytecode to Java 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) * Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) * Convert `gson` integration to use a compile-only source set ([#1510](https://github.com/diffplug/spotless/pull/1510)). * ** POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index b048229b75..5de128bda7 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -33,8 +33,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { - // only run on Java 8 (no benefit to running twice) - enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java index 3e5e1853c7..2ade78f742 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 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. @@ -15,14 +15,11 @@ */ package com.diffplug.spotless.extra.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import java.io.File; import java.util.stream.Stream; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -57,7 +54,7 @@ private static Stream formatWithVersion() { /** New format interface requires source file information to distinguish module-info from compilation unit */ @Nested - @EnabledForJreRange(min = JAVA_11) + class NewFormatInterface extends EclipseResourceHarness { public NewFormatInterface() throws Exception { super(createBuilder(), "module-info.java", getTestResource("java/eclipse/ModuleInfoUnformatted.test"), getTestResource("java/eclipse/ModuleInfoFormatted.test")); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cbcd3bd953..693712cbff 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,14 +4,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Support `jackson()` for YAML files ([#1492](https://github.com/diffplug/spotless/pull/1492)) -* Support `jackson()` for JSON files ([#1492](https://github.com/diffplug/spotless/pull/1492)) -* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) +* Support `jackson()` for YAML and JSON files ([#1492](https://github.com/diffplug/spotless/pull/1492)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed -* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) * **POTENTIALLY BREAKING** Generate the correct qualifiedRuleId for Ktlint 0.48.x [#1495](https://github.com/diffplug/spotless/pull/1495) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) + * You can bump your build JRE without bumping your requirements ([docs](https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation)). +* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. 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 868502d216..91847af0cf 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 @@ -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. @@ -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 { 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."); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index d77b22d0d3..947b5bd728 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -15,35 +15,14 @@ */ package com.diffplug.gradle.spotless; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import java.io.IOException; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; class KotlinExtensionTest extends GradleIntegrationHarness { private static final String HEADER = "// License Header"; private static final String HEADER_WITH_YEAR = "// License Header $YEAR"; - @Test - void integration() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void integrationDiktat() throws IOException { setFile("build.gradle").toLines( @@ -63,45 +42,6 @@ void integrationDiktat() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void integrationKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic.clean"); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void integrationKtfmt_dropboxStyle_0_18() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt('0.18').dropboxStyle()", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -119,42 +59,6 @@ void integrationKtfmt_dropboxStyle_0_19() throws IOException { assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); } - @Test - void testWithIndentation() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint().editorConfigOverride(['indent_size': '6'])", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean-indent6"); - } - - @Test - void withExperimental() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint().setUseExperimental(true)", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimental.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -197,119 +101,6 @@ void testWithHeader() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void testWithHeaderKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader('" + HEADER + "')", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test")); - } - - @Test - void testWithCustomHeaderSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " licenseHeader ('" + HEADER + "', '@file')", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test")); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void testWithCustomHeaderSeparatorKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader ('" + HEADER + "', '@file')", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test")); - } - - @Test - void testWithNonStandardYearSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", - " }", - "}"); - - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); - setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void testWithNonStandardYearSeparatorKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", - " ktfmt()", - " }", - "}"); - - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); - setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -329,70 +120,4 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { - setFile("build.gradle.kts").toLines( - "plugins {", - " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", - " id(\"com.diffplug.spotless\")", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().configure { options ->", - " options.setMaxWidth(120)", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().dropboxStyle().configure { options ->", - " options.maxWidth = 120", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void testWithCustomMaxWidthDropboxStyleKtfmtGradleKts() throws IOException { - setFile("build.gradle.kts").toLines( - "plugins {", - " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", - " id(\"com.diffplug.spotless\")", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().dropboxStyle().configure { options ->", - " options.setMaxWidth(120)", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); - } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 0f3438ffff..13a7cd8472 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -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. @@ -16,65 +16,13 @@ package com.diffplug.gradle.spotless; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; class KotlinGradleExtensionTest extends GradleIntegrationHarness { - @Test - void integration() throws IOException { - testInDirectory(null); - } - - @Test - void integration_script_in_subdir() throws IOException { - testInDirectory("companionScripts"); - } - - private void testInDirectory(final String directory) throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " target '**/*.gradle.kts'", - " }", - "}"); - String filePath = "configuration.gradle.kts"; - if (directory != null) { - filePath = directory + "/" + filePath; - } - setFile(filePath).toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile(filePath).sameAsResource("kotlin/ktlint/basic.clean"); - } - - @Test - void integration_default() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void integration_default_diktat() throws IOException { setFile("build.gradle").toLines( @@ -93,41 +41,6 @@ void integration_default_diktat() throws IOException { assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); } - @Test - void indentStep() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint().userData(['indent_size': '6'])", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessCheck").buildAndFail(); - } - - @Test - void withExperimental() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint().setUseExperimental(true)", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -151,26 +64,6 @@ void withExperimentalEditorConfigOverride() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. - void integration_ktfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktfmt()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/basic.clean"); - } - - @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt_with_dropbox_style() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -187,22 +80,4 @@ void integration_ktfmt_with_dropbox_style() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/dropboxstyle.clean"); } - - @Test - void integration_lint_script_files_without_top_level_declaration() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toContent("buildscript {}"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").hasContent("buildscript {}"); - } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 93dd005ab6..9cda0d2785 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,17 +4,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) - * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features +* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Jackson (`json` and `yaml`) has new `spaceBeforeSeparator` option * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` +* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) + * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) * **POTENTIALLY BREAKING** Generate the correct qualifiedRuleId for Ktlint 0.48.x [#1495](https://github.com/diffplug/spotless/pull/1495) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) + * You can bump your build JRE without bumping your requirements ([docs](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)). * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) -* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index e594c724ef..c4082f52e0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -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; @@ -190,6 +191,16 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { protected abstract void process(Iterable 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()) { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 6fbff78cc7..98a83d612c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 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. @@ -15,10 +15,7 @@ */ package com.diffplug.spotless.maven.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -45,7 +42,6 @@ void specificVersionSpecificStyle() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void specificVersionReflowLongStrings() throws Exception { writePomWithJavaSteps( "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java index 33ec8ea84f..d8d66fa46d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package com.diffplug.spotless.maven.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -34,7 +31,6 @@ void specificVersionDefaultStyle() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void specificJava11Version2() throws Exception { writePomWithJavaSteps( "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 88dcd172e0..4ae266cc23 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -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. @@ -15,14 +15,10 @@ */ package com.diffplug.spotless.maven.kotlin; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; -@EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index cf2a90ad79..ff64b574e1 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -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. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import static org.junit.jupiter.api.condition.JRE.JAVA_13; import static org.junit.jupiter.api.condition.JRE.JAVA_15; @@ -42,7 +41,7 @@ void jvm13Features() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11, max = JAVA_15) // google-java-format requires JRE 11+ + @EnabledForJreRange(max = JAVA_15) // google-java-format requires JRE 11+ void behavior18() throws Exception { FormatterStep step = GoogleJavaFormatStep.create("1.8", TestProvisioner.mavenCentral()); StepHarness.forStep(step) @@ -125,7 +124,6 @@ protected FormatterStep create() { } @Test - @EnabledForJreRange(min = JAVA_11) // google-java-format requires JRE 11+ void equalityGroupArtifact() throws Exception { new SerializableEqualityTester() { String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact(); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index ad358cafc6..dfd59c2655 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import static org.junit.jupiter.api.condition.JRE.JAVA_13; import org.junit.jupiter.api.Test; @@ -38,7 +37,6 @@ void jvm13Features() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void behavior2() throws Exception { FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 3047245298..6700be168d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -88,14 +88,14 @@ void works0_48_1() { @Test void equality() { new SerializableEqualityTester() { - String version = "0.32.0"; + String version = "0.48.0"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.38.0-alpha01"; + version = "0.48.1"; api.areDifferentThan(); } diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java index ddaf1b324b..bfa971fc40 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java @@ -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. @@ -15,32 +15,26 @@ */ package com.diffplug.spotless.kotlin; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.*; @Disabled class KtfmtStepTest extends ResourceHarness { @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void behavior() throws Exception { FormatterStep step = KtfmtStep.create(TestProvisioner.mavenCentral()); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic.clean"); } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_18() throws Exception { FormatterStep step = KtfmtStep.create("0.18", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_19() throws Exception { FormatterStep step = KtfmtStep.create("0.19", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean");