You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2022/10/28 01:45:29 UTC
[beam] branch master updated: Use --release 8 for builds targeting Java 8 (#23771)
This is an automated email from the ASF dual-hosted git repository.
lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new feaa1a277b2 Use --release 8 for builds targeting Java 8 (#23771)
feaa1a277b2 is described below
commit feaa1a277b20ae555fe488000bcffebd8c18a9ed
Author: Liam Miller-Cushon <cu...@google.com>
AuthorDate: Thu Oct 27 18:45:23 2022 -0700
Use --release 8 for builds targeting Java 8 (#23771)
* 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 <lc...@google.com>
* Review feedback
* Update buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
Co-authored-by: Lukasz Cwik <lc...@google.com>
* Adjust javaVersion configuration
Co-authored-by: Lukasz Cwik <lc...@google.com>
---
.../main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy | 9 +++++++++
sdks/java/container/agent/build.gradle | 10 +++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
index fa6bfaf6dec..7e4c8a1674d 100644
--- a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
+++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
@@ -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 -= [
diff --git a/sdks/java/container/agent/build.gradle b/sdks/java/container/agent/build.gradle
index 9d86fd430a6..df3780e4544 100644
--- a/sdks/java/container/agent/build.gradle
+++ b/sdks/java/container/agent/build.gradle
@@ -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
@@ -35,9 +42,7 @@ jar {
}
}
-
if (project.hasProperty('java11Home')) {
- javaVersion = "1.11"
def java11Home = project.findProperty('java11Home')
project.tasks.withType(JavaCompile) {
options.fork = true
@@ -45,7 +50,6 @@ if (project.hasProperty('java11Home')) {
options.compilerArgs += ['-Xlint:-path']
}
} else if (project.hasProperty('java17Home')) {
- javaVersion = "1.17"
project.tasks.withType(JavaCompile) {
setJava17Options(options)