Skip to content

Commit

Permalink
Optionally run Gradle build + ITs using different JDK
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
snazy committed Oct 2, 2023
1 parent c60e23a commit ad127ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions devtools/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@
<gradle.executable>..\gradlew.bat</gradle.executable>
</properties>
</profile>
<profile>
<id>gradleJavaHomeSet</id>
<activation>
<property>
<name>env.GRADLE_JAVA_HOME</name>
</property>
</activation>
<properties>
<gradleJavaHome>${env.GRADLE_JAVA_HOME}</gradleJavaHome>
</properties>
</profile>
<profile>
<id>gradleJavaHomeNotSet</id>
<activation>
<property>
<name>!env.GRADLE_JAVA_HOME</name>
</property>
</activation>
<properties>
<gradleJavaHome>${env.JAVA_HOME}</gradleJavaHome>
</properties>
</profile>
<profile>
<id>run-gradle</id>
<activation>
Expand Down Expand Up @@ -79,6 +101,7 @@
<environmentVariables>
<MAVEN_REPO_LOCAL>${settings.localRepository}</MAVEN_REPO_LOCAL>
<GRADLE_OPTS>${env.MAVEN_OPTS}</GRADLE_OPTS>
<JAVA_HOME>${gradleJavaHome}</JAVA_HOME>
</environmentVariables>
<skip>${skip.gradle.build}</skip>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down

0 comments on commit ad127ed

Please sign in to comment.