Skip to content

Commit

Permalink
Polish "Test Gradle plugin against Gradle 8.2-rc-1"
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Jun 2, 2023
1 parent d6192a0 commit 45ce18e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.JavaApplication;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator;
import org.gradle.jvm.application.tasks.CreateStartScripts;
Expand All @@ -58,8 +59,17 @@ public void execute(Project project) {
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
binCopySpec.setFileMode(0755);
distribution.getContents().with(binCopySpec);
project.getTasks()
.named(SpringBootPlugin.BOOT_RUN_TASK_NAME, BootRun.class)
applyApplicationDefaultJvmArgsToRunTasks(project.getTasks(), javaApplication);
}

private void applyApplicationDefaultJvmArgsToRunTasks(TaskContainer tasks, JavaApplication javaApplication) {
applyApplicationDefaultJvmArgsToRunTask(tasks, javaApplication, SpringBootPlugin.BOOT_RUN_TASK_NAME);
applyApplicationDefaultJvmArgsToRunTask(tasks, javaApplication, SpringBootPlugin.BOOT_TEST_RUN_TASK_NAME);
}

private void applyApplicationDefaultJvmArgsToRunTask(TaskContainer tasks, JavaApplication javaApplication,
String taskName) {
tasks.named(taskName, BootRun.class)
.configure((bootRun) -> bootRun.getConventionMapping()
.map("jvmArgs", javaApplication::getApplicationDefaultJvmArgs));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ private void configureBootTestRunTask(Project project, TaskProvider<ResolveMainC
run.setDescription("Runs this project as a Spring Boot application using the test runtime classpath.");
run.setGroup(ApplicationPlugin.APPLICATION_GROUP);
run.classpath(classpath);
run.getConventionMapping().map("jvmArgs", () -> {
if (project.hasProperty("applicationDefaultJvmArgs")) {
return project.property("applicationDefaultJvmArgs");
}
return Collections.emptyList();
});
run.getMainClass().convention(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName));
configureToolchainConvention(project, run);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class SpringBootPlugin implements Plugin<Project> {

static final String BOOT_RUN_TASK_NAME = "bootRun";

static final String BOOT_TEST_RUN_TASK_NAME = "bootTestRun";

/**
* The name of the {@code developmentOnly} configuration.
* @since 2.3.0
Expand Down

0 comments on commit 45ce18e

Please sign in to comment.