Skip to content

Commit 5af4792

Browse files
committed
Fix issue with hibernate-gradle-plugin testing and explicit test JDK
1 parent 9f2135f commit 5af4792

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

local-build-plugins/src/main/java/org/hibernate/orm/toolchains/JavaModulePlugin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public void execute(JavaCompile compileTask) {
9999
@Override
100100
public void execute(Task task) {
101101
project.getLogger().lifecycle(
102-
"Compiling with '{}'",
103-
compileTask.getJavaCompiler().get().getMetadata().getInstallationPath()
102+
"Compiling with '{}' to release '{}'",
103+
compileTask.getJavaCompiler().get().getMetadata().getInstallationPath(),
104+
compileTask.getOptions().getRelease().get()
104105
);
105106
}
106107
}

tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
import org.apache.tools.ant.filters.ReplaceTokens
6+
import org.gradle.api.internal.provider.DefaultProvider
67

78
plugins {
89
id 'java-gradle-plugin'
@@ -119,6 +120,37 @@ if ( !jdkVersions.explicit ) {
119120
else {
120121
logger.warn( "[WARN] Toolchains are not yet supported for Groovy compilation." +
121122
" Using the JDK that runs Gradle for Groovy compilation." )
123+
if ( jdkVersions.test.explicit && jdkVersions.test.launcher.asInt() > jdkVersions.min.asInt() ) {
124+
// Configure the gradle plugin to also compile test to at most the orm.jdk.min version,
125+
// because the test will have to be able to run with a JVM of version orm.jdk.min
126+
tasks.named( "compileTestJava", JavaCompile ).configure {
127+
options.release = Math.min( jdkVersions.test.compiler.asInt(), jdkVersions.min.asInt() )
128+
}
129+
// Must configure the test launcher to a version <= orm.jdk.max, because the tests invoke gradle,
130+
// which inherently can only run with a JDK up to orm.jdk.max.
131+
// Since we only support running Gradle with JDKs in the range of orm.jdk.min up to orm.jdk.max,
132+
// we use a test java launcher for the latest available/configured JDK version
133+
tasks.named( "test", Test ).configure {
134+
def launcher = javaToolchains.launcherFor {
135+
languageVersion = jdkVersions.min
136+
}
137+
for ( int version = jdkVersions.min.asInt() + 1; version <= jdkVersions.max.asInt(); version++ ) {
138+
launcher = new DefaultProvider(() -> {
139+
try {
140+
return javaToolchains.launcherFor {
141+
languageVersion = JavaLanguageVersion.of( version )
142+
}.get()
143+
}
144+
catch (GradleException ex) {
145+
// JavaToolchainQueryService unfortunately throws an exception if a version is not found,
146+
// so we have to catch the exception and return null here to allow a fallback
147+
return null
148+
}
149+
}).orElse( launcher )
150+
}
151+
javaLauncher = launcher
152+
}
153+
}
122154
}
123155

124156
tasks.publish.enabled !ormBuildDetails.hibernateVersion.isSnapshot

0 commit comments

Comments
 (0)