From ad127ed6e9ac9a6ab2cae27ef56833b7d16a3d10 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Mon, 2 Oct 2023 11:47:47 +0200 Subject: [PATCH] Optionally run Gradle build + ITs using different JDK When the environment variable `GRADLE_JAVA_HOME` is present, it will be used as the `JAVA_HOME` when building `devtools/gradle/` using Gradle via Maven, Gradle devtools integration tests respect the environment variable as well. --- devtools/gradle/pom.xml | 23 +++++++++++++++++++ .../gradle/QuarkusGradleWrapperTestBase.java | 5 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/devtools/gradle/pom.xml b/devtools/gradle/pom.xml index a33447d352441..398af0ca03beb 100644 --- a/devtools/gradle/pom.xml +++ b/devtools/gradle/pom.xml @@ -49,6 +49,28 @@ ..\gradlew.bat + + gradleJavaHomeSet + + + env.GRADLE_JAVA_HOME + + + + ${env.GRADLE_JAVA_HOME} + + + + gradleJavaHomeNotSet + + + !env.GRADLE_JAVA_HOME + + + + ${env.JAVA_HOME} + + run-gradle @@ -79,6 +101,7 @@ ${settings.localRepository} ${env.MAVEN_OPTS} + ${gradleJavaHome} ${skip.gradle.build} diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java index d3f3d8a9254c5..45d2a4d7d683a 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java @@ -84,7 +84,10 @@ public BuildResult runGradleWrapper(boolean expectError, File projectDir, boolea .redirectOutput(logOutput) // Should prevent "fragmented" output (parts of stdout and stderr interleaved) .redirectErrorStream(true); - if (System.getenv("JAVA_HOME") == null) { + if (System.getenv("GRADLE_JAVA_HOME") != null) { + // JAVA_HOME for Gradle explicitly configured. + pb.environment().put("JAVA_HOME", System.getenv("GRADLE_JAVA_HOME")); + } else if (System.getenv("JAVA_HOME") == null || System.getenv("JAVA_HOME").isEmpty()) { // This helps running the tests in IntelliJ w/o configuring an explicit JAVA_HOME env var. pb.environment().put("JAVA_HOME", System.getProperty("java.home")); }