|
3 | 3 | * Copyright Red Hat Inc. and Hibernate Authors
|
4 | 4 | */
|
5 | 5 | import org.apache.tools.ant.filters.ReplaceTokens
|
| 6 | +import org.gradle.api.internal.provider.DefaultProvider |
6 | 7 |
|
7 | 8 | plugins {
|
8 | 9 | id 'java-gradle-plugin'
|
@@ -119,6 +120,37 @@ if ( !jdkVersions.explicit ) {
|
119 | 120 | else {
|
120 | 121 | logger.warn( "[WARN] Toolchains are not yet supported for Groovy compilation." +
|
121 | 122 | " 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 | + } |
122 | 154 | }
|
123 | 155 |
|
124 | 156 | tasks.publish.enabled !ormBuildDetails.hibernateVersion.isSnapshot
|
|
0 commit comments