Skip to content

Commit

Permalink
Use --release 8 for builds targeting Java 8 (apache#23771)
Browse files Browse the repository at this point in the history
* Use --release 8 for builds targeting Java 8

This ensures cross compilation works correctly when building on JDK 11
and targeting Java 8.

* Update buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Co-authored-by: Lukasz Cwik <lcwik@google.com>

* Review feedback

* Update buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Co-authored-by: Lukasz Cwik <lcwik@google.com>

* Adjust javaVersion configuration

Co-authored-by: Lukasz Cwik <lcwik@google.com>
  • Loading branch information
cushon and lukecwik committed Oct 28, 2022
1 parent a62fe8f commit feaa1a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,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 += ['--release', '8']
}
// As we want to add '-Xlint:-deprecation' we intentionally remove '-Xlint:deprecation' from compilerArgs here,
// as intellij is adding this, see https://youtrack.jetbrains.com/issue/IDEA-196615
options.compilerArgs -= [
Expand Down
10 changes: 7 additions & 3 deletions sdks/java/container/agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
plugins {
id 'org.apache.beam.module'
}

if (project.hasProperty('java11Home')) {
javaVersion = "1.11"
} else if (project.hasProperty('java17Home')) {
javaVersion = "1.17"
}

applyJavaNature(
exportJavadoc: false,
publish: false
Expand All @@ -35,17 +42,14 @@ jar {
}
}


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)

Expand Down

0 comments on commit feaa1a2

Please sign in to comment.