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.
|
# 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
|
# 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
|
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 boolean explicit;
|
||||||
private final JavaLanguageVersion baseline;
|
private final JavaLanguageVersion baseline;
|
||||||
|
private final JavaLanguageVersion max;
|
||||||
private final MainJdks main;
|
private final MainJdks main;
|
||||||
private final TestJdks test;
|
private final TestJdks test;
|
||||||
|
|
||||||
public JdkVersionConfig(
|
public JdkVersionConfig(
|
||||||
boolean explicit,
|
boolean explicit,
|
||||||
JavaLanguageVersion baseline,
|
JavaLanguageVersion baseline,
|
||||||
|
JavaLanguageVersion max,
|
||||||
JavaLanguageVersion mainCompileVersion,
|
JavaLanguageVersion mainCompileVersion,
|
||||||
JavaLanguageVersion mainReleaseVersion,
|
JavaLanguageVersion mainReleaseVersion,
|
||||||
JavaLanguageVersion testCompileVersion,
|
JavaLanguageVersion testCompileVersion,
|
||||||
|
@ -46,6 +48,7 @@ public class JdkVersionConfig {
|
||||||
JavaLanguageVersion testLauncherVersion) {
|
JavaLanguageVersion testLauncherVersion) {
|
||||||
this.explicit = explicit;
|
this.explicit = explicit;
|
||||||
this.baseline = baseline;
|
this.baseline = baseline;
|
||||||
|
this.max = max;
|
||||||
this.main = new MainJdks( mainCompileVersion, mainReleaseVersion );
|
this.main = new MainJdks( mainCompileVersion, mainReleaseVersion );
|
||||||
this.test = new TestJdks( testCompileVersion, testReleaseVersion, testLauncherVersion );
|
this.test = new TestJdks( testCompileVersion, testReleaseVersion, testLauncherVersion );
|
||||||
}
|
}
|
||||||
|
@ -58,12 +61,28 @@ public class JdkVersionConfig {
|
||||||
return explicit;
|
return explicit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaLanguageVersion getBaselineVersion() {
|
public JavaLanguageVersion getBaseline() {
|
||||||
return baseline;
|
return baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaLanguageVersion getBaseline() {
|
public String getBaselineStr() {
|
||||||
return baseline;
|
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() {
|
public MainJdks getMain() {
|
||||||
|
@ -140,6 +159,7 @@ public class JdkVersionConfig {
|
||||||
return new JdkVersionConfig(
|
return new JdkVersionConfig(
|
||||||
true,
|
true,
|
||||||
baselineJdkVersion,
|
baselineJdkVersion,
|
||||||
|
maxSupportedJdkVersion,
|
||||||
mainCompileVersion,
|
mainCompileVersion,
|
||||||
mainReleaseVersion,
|
mainReleaseVersion,
|
||||||
testCompileVersion,
|
testCompileVersion,
|
||||||
|
@ -165,6 +185,7 @@ public class JdkVersionConfig {
|
||||||
return new JdkVersionConfig(
|
return new JdkVersionConfig(
|
||||||
false,
|
false,
|
||||||
baselineJdkVersion,
|
baselineJdkVersion,
|
||||||
|
maxSupportedJdkVersion,
|
||||||
gradleJdkVersion,
|
gradleJdkVersion,
|
||||||
baselineJdkVersion,
|
baselineJdkVersion,
|
||||||
gradleJdkVersion,
|
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) {
|
public static JavaLanguageVersion extractVersion(Settings settings, String propertyName) {
|
||||||
final StartParameter startParameters = settings.getGradle().getStartParameter();
|
final StartParameter startParameters = settings.getGradle().getStartParameter();
|
||||||
final String projectProp = startParameters.getProjectProperties().get( propertyName );
|
final String projectProp = startParameters.getProjectProperties().get( propertyName );
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.toolchains;
|
package org.hibernate.orm.toolchains;
|
||||||
|
|
||||||
|
import org.gradle.StartParameter;
|
||||||
import org.gradle.api.JavaVersion;
|
import org.gradle.api.JavaVersion;
|
||||||
import org.gradle.api.Plugin;
|
import org.gradle.api.Plugin;
|
||||||
import org.gradle.api.artifacts.VersionCatalog;
|
import org.gradle.api.artifacts.VersionCatalog;
|
||||||
|
import org.gradle.api.artifacts.VersionCatalogsExtension;
|
||||||
import org.gradle.api.artifacts.VersionConstraint;
|
import org.gradle.api.artifacts.VersionConstraint;
|
||||||
import org.gradle.api.initialization.Settings;
|
import org.gradle.api.initialization.Settings;
|
||||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
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 explicitTestVersion = extractVersion( settings, TEST_JDK_VERSION );
|
||||||
|
|
||||||
final JavaLanguageVersion gradleJdkVersion = JavaLanguageVersion.of( JavaVersion.current().getMajorVersion() );
|
final JavaLanguageVersion gradleJdkVersion = JavaLanguageVersion.of( JavaVersion.current().getMajorVersion() );
|
||||||
final JavaLanguageVersion baselineJdkVersion;
|
final JavaLanguageVersion baselineJdkVersion = getJavaLanguageVersion( settings, "orm.jdk.base" );
|
||||||
final JavaLanguageVersion maxSupportedJdkVersion;
|
final JavaLanguageVersion maxSupportedJdkVersion = getJavaLanguageVersion( settings, "orm.jdk.max" );
|
||||||
// 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 JdkVersionConfig jdkVersionConfig = createVersionConfig(
|
final JdkVersionConfig jdkVersionConfig = createVersionConfig(
|
||||||
explicitMainVersion,
|
explicitMainVersion,
|
||||||
|
@ -54,8 +50,18 @@ public class JdkVersionSettingsPlugin implements Plugin<Settings> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JavaLanguageVersion getJavaLanguageVersion(VersionCatalog jdks, String entryName) {
|
private JavaLanguageVersion getJavaLanguageVersion(Settings settings, String name) {
|
||||||
final VersionConstraint versionConstraint = jdks.findVersion( entryName ).orElseThrow();
|
final StartParameter startParameter = settings.getStartParameter();
|
||||||
return JavaLanguageVersion.of( versionConstraint.getRequiredVersion() );
|
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 {
|
versionCatalogs {
|
||||||
jdks {
|
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 "compatible", "17 or 21"
|
||||||
version "jdbc", "4.2" // Bundled with JDK 11
|
version "jdbc", "4.2" // Bundled with JDK 11
|
||||||
|
|
||||||
// Gradle does bytecode transformation on tests.
|
// Gradle does bytecode transformation on tests.
|
||||||
// You can't use bytecode higher than what Gradle supports, even with toolchains.
|
// You can't use bytecode higher than what Gradle supports, even with toolchains.
|
||||||
version "maxSupportedBytecode", "22"
|
version "maxSupportedBytecode", maxJdk
|
||||||
}
|
}
|
||||||
libs {
|
libs {
|
||||||
def antlrVersion = version "antlr", "4.13.0"
|
def antlrVersion = version "antlr", "4.13.0"
|
||||||
|
|
Loading…
Reference in New Issue