Skip to content

Commit

Permalink
Fix verifyJavaVersion in a few places (apache#32183)
Browse files Browse the repository at this point in the history
* Fix verifyJavaVersion wrong filter

* Add jvm verification to Java Examples Dataflow v1/v2

* Fix java container validateJavaHome run on Java11+ without -Pjava11Home
  • Loading branch information
Abacn authored Aug 14, 2024
1 parent f1f5f77 commit 1eb416e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions runners/google-cloud-dataflow-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ task examplesJavaRunnerV2PreCommit(type: Test) {
task examplesJavaRunnerV2IntegrationTest(type: Test) {
group = "Verification"
dependsOn buildAndPushDockerJavaContainer
if (project.hasProperty("testJavaVersion")) {
dependsOn ":sdks:java:testing:test-utils:verifyJavaVersion${project.property("testJavaVersion")}"
}

systemProperty "beamTestPipelineOptions", JsonOutput.toJson(runnerV2PipelineOptions)

Expand Down
3 changes: 3 additions & 0 deletions runners/google-cloud-dataflow-java/examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ task java21PostCommit() {
task preCommit() {
dependsOn preCommitLegacyWorker
dependsOn preCommitLegacyWorkerImpersonate
if (project.hasProperty("testJavaVersion")) {
dependsOn ":sdks:java:testing:test-utils:verifyJavaVersion${project.property("testJavaVersion")}"
}
}

task verifyPortabilityApi() {
Expand Down
5 changes: 4 additions & 1 deletion sdks/java/container/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ task validateJavaHome {
def requiredForVer = ["11", "17", "21"]
if (requiredForVer.contains(imageJavaVersion)) {
doFirst {
if (JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) < 0) {
return
}
boolean propertyFound = false
// enable to build agent with compatible java versions (11-requiredForVer)
for (def checkVer : requiredForVer) {
Expand All @@ -115,7 +118,7 @@ task validateJavaHome {
}
}
if (!propertyFound) {
throw new GradleException("java${imageJavaVersion}Home or compatible properties required for imageJavaVersion=${imageJavaVersion}. Re-run with -Pjava${imageJavaVersion}Home")
throw new GradleException("System Java needs to have version 11+ or java${imageJavaVersion}Home required for imageJavaVersion=${imageJavaVersion}. Re-run with -Pjava${imageJavaVersion}Home")
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions sdks/java/testing/test-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ dependencies {
provided library.java.jmh_core

testImplementation library.java.junit
testRuntimeOnly project(path: ":runners:direct-java", configuration: "shadowTest")
testRuntimeOnly project(path: ":runners:direct-java", configuration: "shadow")
}

['8', '11', '17', '21'].each {
tasks.create(name: "verifyJavaVersion${it}", type: Test) {
['8', '11', '17', '21'].each { String ver ->
tasks.create(name: "verifyJavaVersion${ver}", type: Test) {
filter {
includeTestsMatching "org.apache.beam.sdk.testutils.jvmverification.JvmVerification.verifyCodeIsCompiledWithJava8"
includeTestsMatching "org.apache.beam.sdk.testutils.jvmverification.JvmVerification.verifyTestCodeIsCompiledWithJava${it}"
includeTestsMatching "org.apache.beam.sdk.testutils.jvmverification.JvmVerification.verifyRunningJVMVersionIs${it}"
includeTestsMatching "org.apache.beam.sdk.testutils.jvmverification.JvmVerification.verifyTestCodeIsCompiledWithJava${ver}"
includeTestsMatching "org.apache.beam.sdk.testutils.jvmverification.JvmVerification.verifyRunningJVMVersionIs${ver}"
}
doLast {
println 'Java verified'
Expand Down

0 comments on commit 1eb416e

Please sign in to comment.