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"));
}