Improve handling of JDK versions
This commit is contained in:
parent
f739fb0665
commit
866ba858a1
|
@ -22,3 +22,7 @@ org.gradle.java.installations.auto-detect=false
|
|||
# We can't rely on Gradle's auto-download of JDKs as it doesn't support EA releases.
|
||||
# See https://github.com/gradle/gradle/blob/fc7ea24f3c525d8d12a4346eb0f15976a6be9414/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinary.java#L114
|
||||
org.gradle.java.installations.auto-download=false
|
||||
|
||||
# externalized definition of JDK versions so that they are available in both Project (build.gradle) and Settings (settings.gradle)
|
||||
orm.jdk.base=17
|
||||
orm.jdk.max=22
|
|
@ -33,12 +33,14 @@ public class JdkVersionConfig {
|
|||
|
||||
private final boolean explicit;
|
||||
private final JavaLanguageVersion baseline;
|
||||
private final JavaLanguageVersion max;
|
||||
private final MainJdks main;
|
||||
private final TestJdks test;
|
||||
|
||||
public JdkVersionConfig(
|
||||
boolean explicit,
|
||||
JavaLanguageVersion baseline,
|
||||
JavaLanguageVersion max,
|
||||
JavaLanguageVersion mainCompileVersion,
|
||||
JavaLanguageVersion mainReleaseVersion,
|
||||
JavaLanguageVersion testCompileVersion,
|
||||
|
@ -46,6 +48,7 @@ public class JdkVersionConfig {
|
|||
JavaLanguageVersion testLauncherVersion) {
|
||||
this.explicit = explicit;
|
||||
this.baseline = baseline;
|
||||
this.max = max;
|
||||
this.main = new MainJdks( mainCompileVersion, mainReleaseVersion );
|
||||
this.test = new TestJdks( testCompileVersion, testReleaseVersion, testLauncherVersion );
|
||||
}
|
||||
|
@ -58,12 +61,28 @@ public class JdkVersionConfig {
|
|||
return explicit;
|
||||
}
|
||||
|
||||
public JavaLanguageVersion getBaselineVersion() {
|
||||
public JavaLanguageVersion getBaseline() {
|
||||
return baseline;
|
||||
}
|
||||
|
||||
public JavaLanguageVersion getBaseline() {
|
||||
return baseline;
|
||||
public String getBaselineStr() {
|
||||
return getBaseline().toString();
|
||||
}
|
||||
|
||||
public JavaLanguageVersion getBaselineVersion() {
|
||||
return getBaseline();
|
||||
}
|
||||
|
||||
public JavaLanguageVersion getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public String getMaxStr() {
|
||||
return getMax().toString();
|
||||
}
|
||||
|
||||
public JavaLanguageVersion getMaxVersion() {
|
||||
return getMax();
|
||||
}
|
||||
|
||||
public MainJdks getMain() {
|
||||
|
@ -140,6 +159,7 @@ public class JdkVersionConfig {
|
|||
return new JdkVersionConfig(
|
||||
true,
|
||||
baselineJdkVersion,
|
||||
maxSupportedJdkVersion,
|
||||
mainCompileVersion,
|
||||
mainReleaseVersion,
|
||||
testCompileVersion,
|
||||
|
@ -165,6 +185,7 @@ public class JdkVersionConfig {
|
|||
return new JdkVersionConfig(
|
||||
false,
|
||||
baselineJdkVersion,
|
||||
maxSupportedJdkVersion,
|
||||
gradleJdkVersion,
|
||||
baselineJdkVersion,
|
||||
gradleJdkVersion,
|
||||
|
@ -174,12 +195,6 @@ public class JdkVersionConfig {
|
|||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaLanguageVersion getJavaLanguageVersion(VersionCatalog jdks, String entryName) {
|
||||
final VersionConstraint versionConstraint = jdks.findVersion( entryName ).orElseThrow();
|
||||
return JavaLanguageVersion.of( versionConstraint.getRequiredVersion() );
|
||||
}
|
||||
|
||||
public static JavaLanguageVersion extractVersion(Settings settings, String propertyName) {
|
||||
final StartParameter startParameters = settings.getGradle().getStartParameter();
|
||||
final String projectProp = startParameters.getProjectProperties().get( propertyName );
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
*/
|
||||
package org.hibernate.orm.toolchains;
|
||||
|
||||
import org.gradle.StartParameter;
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.artifacts.VersionCatalog;
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension;
|
||||
import org.gradle.api.artifacts.VersionConstraint;
|
||||
import org.gradle.api.initialization.Settings;
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
||||
|
@ -31,14 +33,8 @@ public class JdkVersionSettingsPlugin implements Plugin<Settings> {
|
|||
final JavaLanguageVersion explicitTestVersion = extractVersion( settings, TEST_JDK_VERSION );
|
||||
|
||||
final JavaLanguageVersion gradleJdkVersion = JavaLanguageVersion.of( JavaVersion.current().getMajorVersion() );
|
||||
final JavaLanguageVersion baselineJdkVersion;
|
||||
final JavaLanguageVersion maxSupportedJdkVersion;
|
||||
// final VersionCatalogsExtension versionCatalogs = settings.getExtensions().getByType( VersionCatalogsExtension.class );
|
||||
// final VersionCatalog jdkVersions = versionCatalogs.named( "jdks" );
|
||||
// baselineJdkVersion = getJavaLanguageVersion( jdkVersions, "baseline" );
|
||||
// maxSupportedJdkVersion = getJavaLanguageVersion( jdkVersions, "maxSupportedBytecode" );
|
||||
baselineJdkVersion = JavaLanguageVersion.of( "11" );
|
||||
maxSupportedJdkVersion = JavaLanguageVersion.of( "17" );
|
||||
final JavaLanguageVersion baselineJdkVersion = getJavaLanguageVersion( settings, "orm.jdk.base" );
|
||||
final JavaLanguageVersion maxSupportedJdkVersion = getJavaLanguageVersion( settings, "orm.jdk.max" );
|
||||
|
||||
final JdkVersionConfig jdkVersionConfig = createVersionConfig(
|
||||
explicitMainVersion,
|
||||
|
@ -54,8 +50,18 @@ public class JdkVersionSettingsPlugin implements Plugin<Settings> {
|
|||
}
|
||||
|
||||
@NotNull
|
||||
private static JavaLanguageVersion getJavaLanguageVersion(VersionCatalog jdks, String entryName) {
|
||||
final VersionConstraint versionConstraint = jdks.findVersion( entryName ).orElseThrow();
|
||||
return JavaLanguageVersion.of( versionConstraint.getRequiredVersion() );
|
||||
private JavaLanguageVersion getJavaLanguageVersion(Settings settings, String name) {
|
||||
final StartParameter startParameter = settings.getStartParameter();
|
||||
final String fromSysProp = startParameter.getSystemPropertiesArgs().get( name );
|
||||
if ( fromSysProp != null && !fromSysProp.isEmpty() ) {
|
||||
return JavaLanguageVersion.of( fromSysProp );
|
||||
}
|
||||
|
||||
final String fromProjProp = startParameter.getProjectProperties().get( name );
|
||||
if ( fromProjProp != null && !fromProjProp.isEmpty() ) {
|
||||
return JavaLanguageVersion.of( fromProjProp );
|
||||
}
|
||||
|
||||
return JavaLanguageVersion.of( JavaVersion.current().getMajorVersion() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,13 +59,17 @@ dependencyResolutionManagement {
|
|||
|
||||
versionCatalogs {
|
||||
jdks {
|
||||
version "baseline", "17"
|
||||
// see gradle.properties (or set with -D/-P)
|
||||
var String baseJdk = jdkVersions.baseline
|
||||
var String maxJdk = jdkVersions.max
|
||||
|
||||
version "baseline", baseJdk
|
||||
version "compatible", "17 or 21"
|
||||
version "jdbc", "4.2" // Bundled with JDK 11
|
||||
|
||||
// Gradle does bytecode transformation on tests.
|
||||
// You can't use bytecode higher than what Gradle supports, even with toolchains.
|
||||
version "maxSupportedBytecode", "22"
|
||||
version "maxSupportedBytecode", maxJdk
|
||||
}
|
||||
libs {
|
||||
def antlrVersion = version "antlr", "4.13.0"
|
||||
|
|
Loading…
Reference in New Issue