Allow additional JVM args when running tests via toolchain

See gh-27089
pull/27310/head
dreis2211 3 years ago committed by Andy Wilkinson
parent 685b78f504
commit 01b0156fed

@ -17,6 +17,7 @@
package org.springframework.boot.build.toolchain;
import org.gradle.api.Project;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
@ -29,10 +30,13 @@ public class ToolchainExtension {
private final Property<JavaLanguageVersion> maximumCompatibleJavaVersion;
private final ListProperty<String> testJvmArgs;
private final JavaLanguageVersion javaVersion;
public ToolchainExtension(Project project) {
this.maximumCompatibleJavaVersion = project.getObjects().property(JavaLanguageVersion.class);
this.testJvmArgs = project.getObjects().listProperty(String.class);
String toolchainVersion = (String) project.findProperty("toolchainVersion");
this.javaVersion = (toolchainVersion != null) ? JavaLanguageVersion.of(toolchainVersion) : null;
}
@ -41,6 +45,10 @@ public class ToolchainExtension {
return this.maximumCompatibleJavaVersion;
}
public ListProperty<String> getTestJvmArgs() {
return this.testJvmArgs;
}
JavaLanguageVersion getJavaVersion() {
return this.javaVersion;
}

@ -16,9 +16,6 @@
package org.springframework.boot.build.toolchain;
import java.util.Collections;
import java.util.List;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginExtension;
@ -56,7 +53,7 @@ public class ToolchainPlugin implements Plugin<Project> {
JavaToolchainSpec toolchainSpec = project.getExtensions().getByType(JavaPluginExtension.class)
.getToolchain();
toolchainSpec.getLanguageVersion().set(toolchain.getJavaVersion());
configureTestToolchain(project);
configureTestToolchain(project, toolchain);
}
}
@ -71,11 +68,11 @@ public class ToolchainPlugin implements Plugin<Project> {
project.getTasks().withType(Test.class, (task) -> task.setEnabled(false));
}
private void configureTestToolchain(Project project) {
project.getTasks().withType(Test.class, (test) -> {
List<String> arguments = Collections.singletonList("--illegal-access=warn");
test.jvmArgs(arguments);
});
private void configureTestToolchain(Project project, ToolchainExtension toolchain) {
if (!toolchain.getTestJvmArgs().isPresent()) {
return;
}
project.getTasks().withType(Test.class, (test) -> test.jvmArgs(toolchain.getTestJvmArgs().get()));
}
}

@ -9,6 +9,10 @@ plugins {
description = "Spring Boot"
toolchain {
testJvmArgs.add("--add-opens=java.base/java.net=ALL-UNNAMED")
}
def tomcatConfigProperties = "$buildDir/tomcat-config-properties"
configurations {

Loading…
Cancel
Save