Fix Gradle toolchain issues
This commit is contained in:
parent
ffe13dde30
commit
7c697f7e37
|
@ -177,26 +177,6 @@ if ( toolsJar.exists() ) {
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Testing
|
// Testing
|
||||||
|
|
||||||
if ( jdkVersions.explicitlyConfigured ) {
|
|
||||||
tasks.test {
|
|
||||||
// Configure version of Java tools
|
|
||||||
javaLauncher = javaToolchains.launcherFor {
|
|
||||||
languageVersion = gradle.ext.javaVersions.test.launcher
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure JVM Options
|
|
||||||
jvmArgs( getProperty( 'toolchain.launcher.jvmargs' ).toString().split( ' ' ) )
|
|
||||||
if ( project.hasProperty( 'test.jdk.launcher.args' ) ) {
|
|
||||||
jvmArgs( project.getProperty( 'test.jdk.launcher.args' ).toString().split( ' ' ) )
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display version of Java tools
|
|
||||||
doFirst {
|
|
||||||
logger.lifecycle "Testing with '${javaLauncher.get().metadata.installationPath}'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class HeapDumpPathProvider implements CommandLineArgumentProvider {
|
class HeapDumpPathProvider implements CommandLineArgumentProvider {
|
||||||
@OutputDirectory
|
@OutputDirectory
|
||||||
Provider<Directory> path
|
Provider<Directory> path
|
||||||
|
|
|
@ -271,7 +271,7 @@ if ( jdkVersions.test.release.asInt() >= 17 && jdkVersions.explicit ) {
|
||||||
// For the new source set, we need to configure the source and target version to 17
|
// For the new source set, we need to configure the source and target version to 17
|
||||||
compileTestJava17Java {
|
compileTestJava17Java {
|
||||||
javaCompiler = javaToolchains.compilerFor {
|
javaCompiler = javaToolchains.compilerFor {
|
||||||
languageVersion = gradle.ext.javaVersions.test.compiler
|
languageVersion = jdkVersions.test.compiler
|
||||||
}
|
}
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 17
|
||||||
targetCompatibility = 17
|
targetCompatibility = 17
|
||||||
|
@ -295,13 +295,13 @@ if ( jdkVersions.test.release.asInt() >= 17 && jdkVersions.explicit ) {
|
||||||
// We execute the Java 17 tests in a custom test task
|
// We execute the Java 17 tests in a custom test task
|
||||||
task testJava17(type: Test) {
|
task testJava17(type: Test) {
|
||||||
javaLauncher = javaToolchains.launcherFor {
|
javaLauncher = javaToolchains.launcherFor {
|
||||||
languageVersion = gradle.ext.javaVersions.test.launcher
|
languageVersion = jdkVersions.test.launcher
|
||||||
}
|
}
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
testClassesDirs = sourceSets.testJava17.output.classesDirs
|
testClassesDirs = sourceSets.testJava17.output.classesDirs
|
||||||
classpath = sourceSets.testJava17.runtimeClasspath
|
classpath = sourceSets.testJava17.runtimeClasspath
|
||||||
|
|
||||||
if ( gradle.ext.javaVersions.test.launcher.asInt() >= 19 ) {
|
if ( jdkVersions.test.launcher.asInt() >= 19 ) {
|
||||||
logger.warn( "The version of Java bytecode that will be tested is not supported by Byte Buddy by default. " +
|
logger.warn( "The version of Java bytecode that will be tested is not supported by Byte Buddy by default. " +
|
||||||
" Setting 'net.bytebuddy.experimental=true'." )
|
" Setting 'net.bytebuddy.experimental=true'." )
|
||||||
systemProperty 'net.bytebuddy.experimental', true
|
systemProperty 'net.bytebuddy.experimental', true
|
||||||
|
|
|
@ -122,7 +122,7 @@ public abstract class LoggingReportTask extends AbstractJandexAwareTask {
|
||||||
|
|
||||||
private IdRange calculateIdRange(AnnotationInstance msgLoggerAnnUsage, SubSystem subSystem) {
|
private IdRange calculateIdRange(AnnotationInstance msgLoggerAnnUsage, SubSystem subSystem) {
|
||||||
final ClassInfo loggerClassInfo = msgLoggerAnnUsage.target().asClass();
|
final ClassInfo loggerClassInfo = msgLoggerAnnUsage.target().asClass();
|
||||||
getProject().getLogger().lifecycle( "MessageLogger (`%s`) missing id-range", loggerClassInfo.simpleName() );
|
getProject().getLogger().lifecycle( "MessageLogger (`{}`) missing id-range", loggerClassInfo.simpleName() );
|
||||||
|
|
||||||
final List<AnnotationInstance> messageAnnUsages = loggerClassInfo.annotations( MSG_ANN_NAME );
|
final List<AnnotationInstance> messageAnnUsages = loggerClassInfo.annotations( MSG_ANN_NAME );
|
||||||
if ( messageAnnUsages.isEmpty() ) {
|
if ( messageAnnUsages.isEmpty() ) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.gradle.api.tasks.SourceSetContainer;
|
||||||
import org.gradle.api.tasks.compile.CompileOptions;
|
import org.gradle.api.tasks.compile.CompileOptions;
|
||||||
import org.gradle.api.tasks.compile.JavaCompile;
|
import org.gradle.api.tasks.compile.JavaCompile;
|
||||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
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.JavaLanguageVersion;
|
||||||
import org.gradle.jvm.toolchain.JavaToolchainService;
|
import org.gradle.jvm.toolchain.JavaToolchainService;
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
|
|
||||||
final JavaCompile mainCompileTask = (JavaCompile) project.getTasks().getByName( mainSourceSet.getCompileJavaTaskName() );
|
final JavaCompile mainCompileTask = (JavaCompile) project.getTasks().getByName( mainSourceSet.getCompileJavaTaskName() );
|
||||||
final JavaCompile testCompileTask = (JavaCompile) project.getTasks().getByName( testSourceSet.getCompileJavaTaskName() );
|
final JavaCompile testCompileTask = (JavaCompile) project.getTasks().getByName( testSourceSet.getCompileJavaTaskName() );
|
||||||
|
final Test testTask = (Test) project.getTasks().findByName( testSourceSet.getName() );
|
||||||
|
|
||||||
if ( !jdkVersionsConfig.isExplicitlyConfigured() ) {
|
if ( !jdkVersionsConfig.isExplicitlyConfigured() ) {
|
||||||
mainCompileTask.setSourceCompatibility( jdkVersionsConfig.getMainReleaseVersion().toString() );
|
mainCompileTask.setSourceCompatibility( jdkVersionsConfig.getMainReleaseVersion().toString() );
|
||||||
|
@ -63,6 +65,7 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
|
|
||||||
configureCompileTasks( project );
|
configureCompileTasks( project );
|
||||||
configureJavadocTasks( project );
|
configureJavadocTasks( project );
|
||||||
|
configureTestTasks( project );
|
||||||
|
|
||||||
configureCompileTask( mainCompileTask, jdkVersionsConfig.getMainReleaseVersion() );
|
configureCompileTask( mainCompileTask, jdkVersionsConfig.getMainReleaseVersion() );
|
||||||
configureCompileTask( testCompileTask, jdkVersionsConfig.getTestReleaseVersion() );
|
configureCompileTask( testCompileTask, jdkVersionsConfig.getTestReleaseVersion() );
|
||||||
|
@ -72,6 +75,13 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
javaToolchainSpec.getLanguageVersion().set( jdkVersionsConfig.getTestCompileVersion() );
|
javaToolchainSpec.getLanguageVersion().set( jdkVersionsConfig.getTestCompileVersion() );
|
||||||
} )
|
} )
|
||||||
);
|
);
|
||||||
|
if ( testTask != null ) {
|
||||||
|
testTask.getJavaLauncher().set(
|
||||||
|
toolchainService.launcherFor( javaToolchainSpec -> {
|
||||||
|
javaToolchainSpec.getLanguageVersion().set( jdkVersionsConfig.getTestLauncherVersion() );
|
||||||
|
} )
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +107,7 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Task task) {
|
public void execute(Task task) {
|
||||||
project.getLogger().lifecycle(
|
project.getLogger().lifecycle(
|
||||||
"Compiling with '%s'",
|
"Compiling with '{}'",
|
||||||
compileTask.getJavaCompiler().get().getMetadata().getInstallationPath()
|
compileTask.getJavaCompiler().get().getMetadata().getInstallationPath()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +126,7 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Task task) {
|
public void execute(Task task) {
|
||||||
project.getLogger().lifecycle(
|
project.getLogger().lifecycle(
|
||||||
"Generating javadoc with '%s'",
|
"Generating javadoc with '{}}'",
|
||||||
javadocTask.getJavadocTool().get().getMetadata().getInstallationPath()
|
javadocTask.getJavadocTool().get().getMetadata().getInstallationPath()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -125,6 +135,37 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void configureTestTasks(Project project) {
|
||||||
|
project.getTasks().withType( Test.class ).configureEach( new Action<Test>() {
|
||||||
|
@Override
|
||||||
|
public void execute(Test testTask) {
|
||||||
|
getJvmArgs( testTask ).addAll(
|
||||||
|
Arrays.asList(
|
||||||
|
project.property( "toolchain.launcher.jvmargs" ).toString().split( " " )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if ( project.hasProperty( "test.jdk.launcher.args" ) ) {
|
||||||
|
getJvmArgs( testTask ).addAll(
|
||||||
|
Arrays.asList(
|
||||||
|
project.getProperties().get( "test.jdk.launcher.args" ).toString().split( " " )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
testTask.doFirst(
|
||||||
|
new Action<Task>() {
|
||||||
|
@Override
|
||||||
|
public void execute(Task task) {
|
||||||
|
project.getLogger().lifecycle(
|
||||||
|
"Testing with '{}'",
|
||||||
|
testTask.getJavaLauncher().get().getMetadata().getInstallationPath()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
private static List<String> javadocFlags(Project project) {
|
private static List<String> javadocFlags(Project project) {
|
||||||
final String jvmArgs = project.property( "toolchain.javadoc.jvmargs" ).toString();
|
final String jvmArgs = project.property( "toolchain.javadoc.jvmargs" ).toString();
|
||||||
final String[] splits = jvmArgs.split( " " );
|
final String[] splits = jvmArgs.split( " " );
|
||||||
|
@ -145,4 +186,16 @@ public class JavaModulePlugin implements Plugin<Project> {
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getJvmArgs(Test testTask) {
|
||||||
|
final List<String> existing = testTask.getJvmArgs();
|
||||||
|
if ( existing == null || !( existing instanceof ArrayList ) ) {
|
||||||
|
final List<String> target = new ArrayList<>();
|
||||||
|
testTask.setJvmArgs( target );
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,10 +124,10 @@ public class JdkVersionConfig {
|
||||||
testCompileVersion = requireNonNullElse( explicitTestVersion, baselineJdkVersion );
|
testCompileVersion = requireNonNullElse( explicitTestVersion, baselineJdkVersion );
|
||||||
mainReleaseVersion = baselineJdkVersion;
|
mainReleaseVersion = baselineJdkVersion;
|
||||||
|
|
||||||
if ( testCompileVersion.asInt() > gradleJdkVersion.asInt() ) {
|
if ( testCompileVersion.asInt() > maxSupportedJdkVersion.asInt() ) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"[WARN] Gradle does not support bytecode version '${testCompilerVersion}'."
|
"[WARN] Gradle does not support bytecode version '" + testCompileVersion + "'."
|
||||||
+ " Forcing test bytecode to version ${GRADLE_MAX_SUPPORTED_BYTECODE_VERSION}."
|
+ " Forcing test bytecode to version " + maxSupportedJdkVersion + "."
|
||||||
);
|
);
|
||||||
testReleaseVersion = maxSupportedJdkVersion;
|
testReleaseVersion = maxSupportedJdkVersion;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public class JdkVersionConfig {
|
||||||
testLauncherVersion = testCompileVersion;
|
testLauncherVersion = testCompileVersion;
|
||||||
|
|
||||||
return new JdkVersionConfig(
|
return new JdkVersionConfig(
|
||||||
false,
|
true,
|
||||||
baselineJdkVersion,
|
baselineJdkVersion,
|
||||||
mainCompileVersion,
|
mainCompileVersion,
|
||||||
mainReleaseVersion,
|
mainReleaseVersion,
|
||||||
|
|
|
@ -130,8 +130,8 @@ tasks.withType( JavaCompile ) {
|
||||||
|
|
||||||
if ( !jdkVersions.explicit ) {
|
if ( !jdkVersions.explicit ) {
|
||||||
tasks.withType( GroovyCompile ) {
|
tasks.withType( GroovyCompile ) {
|
||||||
sourceCompatibility = JavaVersion.toVersion( gradle.jdkVersions.baseline )
|
sourceCompatibility = JavaVersion.toVersion( jdkVersions.baseline )
|
||||||
targetCompatibility = JavaVersion.toVersion( gradle.jdkVersions.baseline )
|
targetCompatibility = JavaVersion.toVersion( jdkVersions.baseline )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -53,7 +53,7 @@ if ( jdkVersions.test.release.asInt() >= 17 && jdkVersions.explicit ) {
|
||||||
//compileTestJava17Java {
|
//compileTestJava17Java {
|
||||||
compileTestJava {
|
compileTestJava {
|
||||||
javaCompiler = javaToolchains.compilerFor {
|
javaCompiler = javaToolchains.compilerFor {
|
||||||
languageVersion = gradle.jdkVersions.test.compile
|
languageVersion = jdkVersions.test.compile
|
||||||
}
|
}
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 17
|
||||||
targetCompatibility = 17
|
targetCompatibility = 17
|
||||||
|
@ -61,10 +61,10 @@ if ( jdkVersions.test.release.asInt() >= 17 && jdkVersions.explicit ) {
|
||||||
|
|
||||||
test {
|
test {
|
||||||
javaLauncher = javaToolchains.launcherFor {
|
javaLauncher = javaToolchains.launcherFor {
|
||||||
languageVersion = gradle.ext.javaVersions.test.launcher
|
languageVersion = jdkVersions.test.launcher
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( gradle.ext.javaVersions.test.launcher.asInt() >= 19 ) {
|
if ( jdkVersions.test.launcher.asInt() >= 19 ) {
|
||||||
logger.warn( "The version of Java bytecode that will be tested is not supported by Bytebuddy by default. " +
|
logger.warn( "The version of Java bytecode that will be tested is not supported by Bytebuddy by default. " +
|
||||||
" Setting 'net.bytebuddy.experimental=true'." )
|
" Setting 'net.bytebuddy.experimental=true'." )
|
||||||
systemProperty 'net.bytebuddy.experimental', true
|
systemProperty 'net.bytebuddy.experimental', true
|
||||||
|
|
Loading…
Reference in New Issue