Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ stage('Configure') {
// Don't build with HANA by default, but only do it nightly until we receive a 3rd instance
// new BuildEnvironment( dbName: 'hana_cloud', dbLockableResource: 'hana-cloud', dbLockResourceAsHost: true ),
new BuildEnvironment( node: 's390x' ),
// We build with JDK 21, but produce Java 17 bytecode, so we test with JDK 17, to be sure everything works.
new BuildEnvironment( testJdkVersion: '17' ),
// We generally build with JDK 21, but our baseline is Java 17, so we test with JDK 17, to be sure everything works.
// Here we even compile the main code with JDK 17, to be sure no JDK 18+ classes are depended on.
new BuildEnvironment( mainJdkVersion: '17', testJdkVersion: '17' ),
// We want to enable preview features when testing newer builds of OpenJDK:
// even if we don't use these features, just enabling them can cause side effects
// and it's useful to test that.
new BuildEnvironment( testJdkVersion: '23', testJdkLauncherArgs: '--enable-preview', skipJacoco: true ),
new BuildEnvironment( testJdkVersion: '24', testJdkLauncherArgs: '--enable-preview', skipJacoco: true ),
new BuildEnvironment( testJdkVersion: '23', testJdkLauncherArgs: '--enable-preview', additionalOptions: '-PskipJacoco=true' ),
new BuildEnvironment( testJdkVersion: '24', testJdkLauncherArgs: '--enable-preview', additionalOptions: '-PskipJacoco=true' ),
// The following JDKs aren't supported by Hibernate ORM out-of-the box yet:
// they require the use of -Dnet.bytebuddy.experimental=true.
// Make sure to remove that argument as soon as possible
// -- generally that requires upgrading bytebuddy after the JDK goes GA.
new BuildEnvironment( testJdkVersion: '25', testJdkLauncherArgs: '--enable-preview -Dnet.bytebuddy.experimental=true', skipJacoco: true ),
new BuildEnvironment( testJdkVersion: '25', testJdkLauncherArgs: '--enable-preview -Dnet.bytebuddy.experimental=true', additionalOptions: '-PskipJacoco=true' ),
];

if ( env.CHANGE_ID ) {
Expand Down Expand Up @@ -102,13 +103,18 @@ stage('Build') {
Map<String, Map<String, String>> state = [:]
environments.each { BuildEnvironment buildEnv ->
// Don't build environments for newer JDKs when this is a PR, unless the PR is labelled with 'jdk' or 'jdk-<version>'
if ( helper.scmSource.pullRequest && buildEnv.testJdkVersion &&
if ( helper.scmSource.pullRequest &&
buildEnv.testJdkVersion && buildEnv.testJdkVersion.toInteger() > DEFAULT_JDK_VERSION.toInteger() &&
!pullRequest.labels.contains( 'jdk' ) && !pullRequest.labels.contains( "jdk-${buildEnv.testJdkVersion}" ) ) {
return
}
state[buildEnv.tag] = [:]
executions.put(buildEnv.tag, {
runBuildOnNode(buildEnv.node ?: NODE_PATTERN_BASE) {
def mainJavaHome
if ( buildEnv.mainJdkVersion ) {
mainJavaHome = tool(name: "OpenJDK ${buildEnv.mainJdkVersion} Latest", type: 'jdk')
}
def testJavaHome
if ( buildEnv.testJdkVersion ) {
testJavaHome = tool(name: "OpenJDK ${buildEnv.testJdkVersion} Latest", type: 'jdk')
Expand All @@ -118,9 +124,17 @@ stage('Build') {
// See https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md
withEnv(["JAVA_HOME=${javaHome}", "PATH+JAVA=${javaHome}/bin"]) {
state[buildEnv.tag]['additionalOptions'] = '-PmavenMirror=nexus-load-balancer-c4cf05fd92f43ef8.elb.us-east-1.amazonaws.com'
if ( testJavaHome ) {
if ( buildEnv.mainJdkVersion ) {
state[buildEnv.tag]['additionalOptions'] = state[buildEnv.tag]['additionalOptions'] +
" -Pmain.jdk.version=${buildEnv.mainJdkVersion}"
}
if ( buildEnv.testJdkVersion ) {
state[buildEnv.tag]['additionalOptions'] = state[buildEnv.tag]['additionalOptions'] +
" -Ptest.jdk.version=${buildEnv.testJdkVersion} -Porg.gradle.java.installations.paths=${javaHome},${testJavaHome}"
" -Ptest.jdk.version=${buildEnv.testJdkVersion}"
}
if ( buildEnv.mainJdkVersion || buildEnv.testJdkVersion ) {
state[buildEnv.tag]['additionalOptions'] = state[buildEnv.tag]['additionalOptions'] +
" -Porg.gradle.java.installations.paths=${[javaHome, mainJavaHome, testJavaHome].findAll { it != null }.join(',')}"
}
if ( buildEnv.testJdkLauncherArgs ) {
state[buildEnv.tag]['additionalOptions'] = state[buildEnv.tag]['additionalOptions'] +
Expand All @@ -130,10 +144,6 @@ stage('Build') {
state[buildEnv.tag]['additionalOptions'] = state[buildEnv.tag]['additionalOptions'] +
" -Pci.node=${buildEnv.node}"
}
if ( buildEnv.skipJacoco ) {
state[buildEnv.tag]['additionalOptions'] = state[buildEnv.tag]['additionalOptions'] +
" -PskipJacoco=true"
}
state[buildEnv.tag]['containerName'] = null;
stage('Checkout') {
checkout scm
Expand Down Expand Up @@ -210,6 +220,7 @@ stage('Build') {
// Job-specific helpers

class BuildEnvironment {
String mainJdkVersion
String testJdkVersion
String testJdkLauncherArgs
String dbName = 'h2'
Expand All @@ -219,7 +230,6 @@ class BuildEnvironment {
String additionalOptions
String notificationRecipients
boolean longRunning
boolean skipJacoco

String toString() { getTag() }
String getTag() { "${node ? node + "_" : ''}${testJdkVersion ? 'jdk_' + testJdkVersion + '_' : '' }${dbName}" }
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ 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.min=21
orm.jdk.max=24
# See gradlew/wrapper/gradle-wrapper.properties, https://docs.gradle.org/current/userguide/compatibility.html#java_runtime
orm.jdk.max=22
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.compile.CompileOptions;
import org.gradle.api.tasks.compile.ForkOptions;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.testing.Test;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaToolchainService;

/**
Expand Down Expand Up @@ -54,74 +52,65 @@ public void apply(Project project) {

final SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
final SourceSet mainSourceSet = sourceSets.getByName( SourceSet.MAIN_SOURCE_SET_NAME );
final SourceSet testSourceSet = sourceSets.getByName( SourceSet.TEST_SOURCE_SET_NAME );

final JavaCompile mainCompileTask = (JavaCompile) project.getTasks().getByName( mainSourceSet.getCompileJavaTaskName() );
final JavaCompile testCompileTask = (JavaCompile) project.getTasks().getByName( testSourceSet.getCompileJavaTaskName() );
final Test testTask = (Test) project.getTasks().findByName( testSourceSet.getName() );

if ( !jdkVersionsConfig.isExplicitlyConfigured() ) {
mainCompileTask.setSourceCompatibility( jdkVersionsConfig.getMainReleaseVersion().toString() );
mainCompileTask.setTargetCompatibility( jdkVersionsConfig.getMainReleaseVersion().toString() );

testCompileTask.setSourceCompatibility( jdkVersionsConfig.getTestCompilerVersion().toString() );
testCompileTask.setTargetCompatibility( jdkVersionsConfig.getTestCompilerVersion().toString() );
}
else {
if ( jdkVersionsConfig.getMain().isExplicit() ) {
javaPluginExtension.getToolchain().getLanguageVersion().set( jdkVersionsConfig.getMainCompilerVersion() );

configureCompileTasks( project );
configureTestTasks( project );
configureJavadocTasks( project, mainSourceSet );

configureCompileTask( mainCompileTask, jdkVersionsConfig.getMainReleaseVersion() );
configureCompileTask( testCompileTask, jdkVersionsConfig.getTestReleaseVersion() );

testCompileTask.getJavaCompiler().set(
toolchainService.compilerFor( javaToolchainSpec -> {
javaToolchainSpec.getLanguageVersion().set( jdkVersionsConfig.getTestCompilerVersion() );
} )
);
if ( testTask != null ) {
testTask.getJavaLauncher().set(
toolchainService.launcherFor( javaToolchainSpec -> {
javaToolchainSpec.getLanguageVersion().set( jdkVersionsConfig.getTestLauncherVersion() );
} )
);
}
}
}

private void configureCompileTask(JavaCompile compileTask, JavaLanguageVersion releaseVersion) {
final CompileOptions compileTaskOptions = compileTask.getOptions();
compileTaskOptions.getRelease().set( releaseVersion.asInt() );
// Needs add-opens because of https://github.com/gradle/gradle/issues/15538
addJvmArgs( compileTask, "--add-opens", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" );
configureCompileTasks( project, mainSourceSet, jdkVersionsConfig );
configureTestTasks( project, jdkVersionsConfig );
configureJavadocTasks( project, mainSourceSet, jdkVersionsConfig );
}

private void configureCompileTasks(Project project) {
private void configureCompileTasks(Project project, SourceSet mainSourceSet, JdkVersionConfig jdkVersionsConfig) {
project.getTasks().withType( JavaCompile.class ).configureEach( new Action<JavaCompile>() {
@Override
public void execute(JavaCompile compileTask) {
addJvmArgs( compileTask,
project.property( "toolchain.compiler.jvmargs" ).toString().split( " " )
);
compileTask.doFirst(
new Action<Task>() {
@Override
public void execute(Task task) {
project.getLogger().lifecycle(
"Compiling with '{}'",
compileTask.getJavaCompiler().get().getMetadata().getInstallationPath()
);
if ( compileTask.getName().equals( mainSourceSet.getCompileJavaTaskName() ) ) {
compileTask.getOptions().getRelease().set( jdkVersionsConfig.getMainReleaseVersion().asInt() );
if ( jdkVersionsConfig.getMain().isExplicit() ) {
compileTask.getJavaCompiler().set(
toolchainService.compilerFor( javaToolchainSpec -> {
javaToolchainSpec.getLanguageVersion()
.set( jdkVersionsConfig.getMainCompilerVersion() );
} )
);
}
}
// Assume all non-main compile tasks are test compile tasks,
// because that's currently true,
// and there is no way to automatically determine whether a custom compile task if for main code or tests.
else {
compileTask.getOptions().getRelease().set( jdkVersionsConfig.getTestReleaseVersion().asInt() );
if ( jdkVersionsConfig.getTest().isExplicit() ) {
compileTask.getJavaCompiler().set(
toolchainService.compilerFor( javaToolchainSpec -> {
javaToolchainSpec.getLanguageVersion().set( jdkVersionsConfig.getTestCompilerVersion() );
} )
);
}
}
if ( jdkVersionsConfig.isExplicit() ) {
compileTask.doFirst(
new Action<Task>() {
@Override
public void execute(Task task) {
project.getLogger().lifecycle(
"Compiling with '{}'",
compileTask.getJavaCompiler().get().getMetadata().getInstallationPath()
);
}
}
}
);
);
}
}
} );
}

private void configureTestTasks(Project project) {
private void configureTestTasks(Project project, JdkVersionConfig jdkVersionsConfig) {
project.getTasks().withType( Test.class ).configureEach( new Action<Test>() {
@Override
public void execute(Test testTask) {
Expand All @@ -137,33 +126,45 @@ public void execute(Test testTask) {
)
);
}
testTask.doFirst(
new Action<Task>() {
@Override
public void execute(Task task) {
project.getLogger().lifecycle(
"Testing with '{}'",
testTask.getJavaLauncher().get().getMetadata().getInstallationPath()
);
if ( jdkVersionsConfig.getTest().isExplicit() ) {
testTask.getJavaLauncher().set(
toolchainService.launcherFor( javaToolchainSpec -> {
javaToolchainSpec.getLanguageVersion()
.set( jdkVersionsConfig.getTestLauncherVersion() );
} )
);
}
if ( jdkVersionsConfig.isExplicit() ) {
testTask.doFirst(
new Action<Task>() {
@Override
public void execute(Task task) {
project.getLogger().lifecycle(
"Testing with '{}'",
testTask.getJavaLauncher().get().getMetadata().getInstallationPath()
);
}
}
}
);
);
}
}
} );
}

private void configureJavadocTasks(Project project, SourceSet mainSourceSet) {
private void configureJavadocTasks(Project project, SourceSet mainSourceSet, JdkVersionConfig jdkVersionsConfig) {
project.getTasks().named( mainSourceSet.getJavadocTaskName(), Javadoc.class, (task) -> {
task.getOptions().setJFlags( javadocFlags( project ) );
task.doFirst( new Action<Task>() {
@Override
public void execute(Task t) {
project.getLogger().lifecycle(
"Generating javadoc with '{}'",
task.getJavadocTool().get().getMetadata().getInstallationPath()
);
}
} );
if ( jdkVersionsConfig.isExplicit() ) {
task.doFirst( new Action<Task>() {
@Override
public void execute(Task t) {
project.getLogger().lifecycle(
"Generating javadoc with '{}'",
task.getJavadocTool().get().getMetadata().getInstallationPath()
);
}
} );
}
} );
}

Expand Down
Loading