Skip to content

Commit

Permalink
Remove support for JDK 9 and 10
Browse files Browse the repository at this point in the history
This allows using the --should-stop=ifError=FLOW syntax
  • Loading branch information
tbroyer committed Oct 20, 2024
1 parent 503d4cb commit 66b132e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ This plugin configures `JavaCompile` tasks to use [Error Prone].
## Requirements

> [!IMPORTANT]
> This plugin requires using at least Gradle 6.8 and JDK 9 (for compilation; it's OK to use JDK 8 to run Gradle as long as compilations use at least JDK 9 through [Gradle Java Toolchains][gradle-toolchains]).
> This plugin requires using at least Gradle 6.8 and JDK 11 (for compilation; it's OK to use JDK 8 to run Gradle as long as compilations use at least JDK 11 through [Gradle Java Toolchains][gradle-toolchains]).
The exact minimum required version of the JDK depends on the version of Error Prone being used (independently of the version of this plugin);
there's no forward compatibility guarantee though so older versions of Error Prone aren't necessarily compatible with newer versions of the JDK.

| Error Prone version | Minimum JDK version |
| :------------------: | :-----------------: |
| Up to 2.10 | 9 |
| From 2.10 up to 2.31 | 11 |
| Up to 2.31 | 11 |
| Starting from 2.32 | 17 |

You can still compile down to Java 8 bytecode though, by using JDK 9+ support for `--release 8` (which you can configure with Gradle using [`options.release`][CompileOptions.release]), or with `-source` / `-target` / `-bootclasspath` (configured with Gradle using [`sourceCompatibility`][JavaCompile.sourceCompatibility] / [`targetCompatibility`][JavaCompile.targetCompatibility] / [`options.bootstrapClasspath`][CompileOptions.bootstrapClasspath]).
You can still compile down to a Java version bytecode though, by using javac's support for `--release` (which you can configure with Gradle using [`options.release`][CompileOptions.release]), or with `-source` / `-target` / `-bootclasspath` (configured with Gradle using [`sourceCompatibility`][JavaCompile.sourceCompatibility] / [`targetCompatibility`][JavaCompile.targetCompatibility] / [`options.bootstrapClasspath`][CompileOptions.bootstrapClasspath]).

```kotlin
tasks.withType<JavaCompile>().configureEach {
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/net/ltgt/gradle/errorprone/ErrorPronePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ErrorPronePlugin @Inject constructor(

const val CONFIGURATION_NAME = "errorprone"

internal const val TOO_OLD_TOOLCHAIN_ERROR_MESSAGE = "Must not enable ErrorProne when compiling with JDK < 9"
internal const val TOO_OLD_TOOLCHAIN_ERROR_MESSAGE = "Must not enable ErrorProne when compiling with JDK < 11"

private val HAS_JVM_ARGUMENT_PROVIDERS = GradleVersion.current() >= GradleVersion.version("7.1")

Expand Down Expand Up @@ -112,7 +112,7 @@ class ErrorPronePlugin @Inject constructor(
doFirst("Configure forking for errorprone") {
if (!errorproneOptions.isEnabled.getOrElse(false)) return@doFirst
jvmArgumentProvider.compilerVersion?.let {
if (it < JavaVersion.VERSION_1_9) throw UnsupportedOperationException(TOO_OLD_TOOLCHAIN_ERROR_MESSAGE)
if (it < JavaVersion.VERSION_11) throw UnsupportedOperationException(TOO_OLD_TOOLCHAIN_ERROR_MESSAGE)
if ((it == JavaVersion.current() && CURRENT_JVM_NEEDS_FORKING) && !options.isFork) options.isFork = true
}
}
Expand All @@ -123,7 +123,7 @@ class ErrorPronePlugin @Inject constructor(
project.configurations[annotationProcessorConfigurationName].extendsFrom(errorproneConfiguration)
project.tasks.named<JavaCompile>(compileJavaTaskName) {
options.errorprone {
isEnabled.convention(javaCompiler.map { it.metadata.languageVersion.asInt() >= 9 }.orElse(true))
isEnabled.convention(javaCompiler.map { it.metadata.languageVersion.asInt() >= 11 }.orElse(true))
isCompilingTestOnlyCode.convention(this@configureEach.name.matches(TEST_SOURCE_SET_NAME_REGEX))
}
}
Expand All @@ -150,7 +150,7 @@ internal class ErrorProneJvmArgumentProvider(
override fun asArguments(): Iterable<String> = when {
!errorproneOptions.isEnabled.getOrElse(false) -> emptyList()
compilerVersion == null -> emptyList()
compilerVersion!! >= JavaVersion.VERSION_1_9 -> ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION
compilerVersion!! >= JavaVersion.VERSION_11 -> ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION
else -> emptyList()
}
}
Expand All @@ -170,7 +170,7 @@ internal class ErrorProneCompilerArgumentProvider(

override fun asArguments(): Iterable<String> {
return when {
errorproneOptions.isEnabled.getOrElse(false) -> listOf("-Xplugin:ErrorProne $errorproneOptions", "-XDcompilePolicy=simple", "-XDshould-stop.ifError=FLOW")
errorproneOptions.isEnabled.getOrElse(false) -> listOf("-Xplugin:ErrorProne $errorproneOptions", "-XDcompilePolicy=simple", "--should-stop=ifError=FLOW")
else -> emptyList()
}
}
Expand Down

0 comments on commit 66b132e

Please sign in to comment.