lukecwik commented on code in PR #23771:
URL: https://github.com/apache/beam/pull/23771#discussion_r1003787585
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy:
##########
@@ -913,6 +913,15 @@ class BeamModulePlugin implements Plugin<Project> {
project.tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
+ // Use --release 8 when targeting Java 8 and running on JDK > 8
+ //
+ // Consider migrating compilation and testing to use JDK 9+ and
setting '--release=8' as
+ // the default allowing 'applyJavaNature' to override it for the few
modules that need JDK 9+
+ // artifacts. See https://stackoverflow.com/a/43103038/4368200 for
additional details.
+ if
(JavaVersion.VERSION_1_8.compareTo(JavaVersion.toVersion(project.javaVersion))
== 0
+ && JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) < 0) {
+ options.compilerArgs.addAll(['--release', '8'])
Review Comment:
```suggestion
options.compilerArgs += ['--release', '8']
```
##########
sdks/java/container/agent/build.gradle:
##########
@@ -59,6 +59,7 @@ if (project.hasProperty('java11Home')) {
project.tasks.each {
it.onlyIf {
project.hasProperty('java11Home') || project.hasProperty('java17Home')
- || JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) < 0
+ || (JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) < 0
+ &&
JavaVersion.VERSION_1_8.compareTo(JavaVersion.toVersion(project.javaVersion)) <
0)
Review Comment:
I think the issue is that `applyJavaNature` is occurring before:
```
if (project.hasProperty('java11Home')) {
javaVersion = "1.11"
def java11Home = project.findProperty('java11Home')
project.tasks.withType(JavaCompile) {
options.fork = true
options.forkOptions.javaHome = java11Home as File
options.compilerArgs += ['-Xlint:-path']
}
} else if (project.hasProperty('java17Home')) {
javaVersion = "1.17"
project.tasks.withType(JavaCompile) {
setJava17Options(options)
checkerFramework {
skipCheckerFramework = true
}
}
}
```
which means that `javaVersion = 8` and hence `--release 8` is being added.
Moving the `if block` to before `applyJavaVersion` would resolve this.
##########
sdks/java/testing/jpms-tests/build.gradle:
##########
@@ -134,6 +134,7 @@ plugins.withType(JavaPlugin).configureEach{
project.tasks.each {
it.onlyIf {
project.hasProperty("compileAndRunTestsWithJava17")
- || JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) < 0
+ || (JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) < 0
+ &&
JavaVersion.VERSION_1_8.compareTo(JavaVersion.toVersion(project.javaVersion)) <
0)
Review Comment:
This is redundant since `javaVersion` is specified as `1.11` before
`applyJavaNature`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]