Automatically create developmentOnly configuration
Previously, the developmentOnly configuration, typically used for Devtools, had to be declared manually. The BootJar and BootWar tasks then had a property, excludeDevtools, that could be used to control whether or not Devtools would be excluded from the executable archive. This commit updates the reaction to the Java plugin being applied to automatically create the developmentOnly configuration. The classpaths of bootJar and bootWar are then configured not to include the contents of the developmentOnly configuration. As a result of this, the excludeDevtools property is no longer needed and has been deprecated. Its default has also been changed from true to false to make it easy to opt in to Devtools, when configured as a development-only dependency, being included in executable jars and wars by adding developmentOnly to the classpath of the archive task. Closes gh-16599
This commit is contained in:
@@ -27,6 +27,7 @@ import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
|
||||
import org.gradle.api.plugins.ApplicationPlugin;
|
||||
@@ -67,6 +68,7 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||
public void execute(Project project) {
|
||||
disableJarTask(project);
|
||||
configureBuildTask(project);
|
||||
configureDevelopmentOnlyConfiguration(project);
|
||||
TaskProvider<BootJar> bootJar = configureBootJarTask(project);
|
||||
configureBootBuildImageTask(project, bootJar);
|
||||
configureArtifactPublication(bootJar);
|
||||
@@ -92,7 +94,8 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||
bootJar.setGroup(BasePlugin.BUILD_GROUP);
|
||||
SourceSet mainSourceSet = javaPluginConvention(project).getSourceSets()
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
bootJar.classpath((Callable<FileCollection>) mainSourceSet::getRuntimeClasspath);
|
||||
bootJar.classpath((Callable<FileCollection>) () -> mainSourceSet.getRuntimeClasspath().minus(
|
||||
project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME)));
|
||||
bootJar.conventionMapping("mainClassName", new MainClassConvention(project, bootJar::getClasspath));
|
||||
});
|
||||
}
|
||||
@@ -157,6 +160,15 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||
compile.doFirst(new AdditionalMetadataLocationsConfigurer());
|
||||
}
|
||||
|
||||
private void configureDevelopmentOnlyConfiguration(Project project) {
|
||||
Configuration developmentOnly = project.getConfigurations()
|
||||
.create(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
|
||||
developmentOnly
|
||||
.setDescription("Configuration for development-only dependencies such as Spring Boot's DevTools.");
|
||||
project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
|
||||
.extendsFrom(developmentOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task {@link Action} to add additional meta-data locations. We need to use an
|
||||
* inner-class rather than a lambda due to
|
||||
|
||||
@@ -70,6 +70,12 @@ public class SpringBootPlugin implements Plugin<Project> {
|
||||
*/
|
||||
public static final String BOOT_BUILD_IMAGE_TASK_NAME = "bootBuildImage";
|
||||
|
||||
/**
|
||||
* The name of the {@code developmentOnly} configuration.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static final String DEVELOPMENT_ONLY_CONFIGURATION_NAME = "developmentOnly";
|
||||
|
||||
/**
|
||||
* The coordinates {@code (group:name:version)} of the
|
||||
* {@code spring-boot-dependencies} bom.
|
||||
|
||||
@@ -19,7 +19,8 @@ package org.springframework.boot.gradle.plugin;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
|
||||
import org.gradle.api.plugins.BasePlugin;
|
||||
import org.gradle.api.plugins.WarPlugin;
|
||||
@@ -63,12 +64,15 @@ class WarPluginAction implements PluginApplicationAction {
|
||||
bootWar.setDescription("Assembles an executable war archive containing webapp"
|
||||
+ " content, and the main classes and their dependencies.");
|
||||
bootWar.providedClasspath(providedRuntimeConfiguration(project));
|
||||
bootWar.setClasspath(bootWar.getClasspath().minus(
|
||||
project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME)));
|
||||
bootWar.conventionMapping("mainClassName", new MainClassConvention(project, bootWar::getClasspath));
|
||||
});
|
||||
}
|
||||
|
||||
private Configuration providedRuntimeConfiguration(Project project) {
|
||||
return project.getConfigurations().getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME);
|
||||
private FileCollection providedRuntimeConfiguration(Project project) {
|
||||
ConfigurationContainer configurations = project.getConfigurations();
|
||||
return configurations.getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME);
|
||||
}
|
||||
|
||||
private void configureArtifactPublication(TaskProvider<BootWar> bootWar) {
|
||||
|
||||
@@ -118,15 +118,21 @@ public interface BootArchive extends Task {
|
||||
* {@code false}.
|
||||
* @return {@code true} if the Devtools jar should be excluded, or {@code false} if
|
||||
* not
|
||||
* @deprecated since 2.3.0 in favour of configuring a classpath that does not include
|
||||
* development-only dependencies
|
||||
*/
|
||||
@Input
|
||||
@Deprecated
|
||||
boolean isExcludeDevtools();
|
||||
|
||||
/**
|
||||
* Sets whether or not the Devtools jar should be excluded.
|
||||
* @param excludeDevtools {@code true} if the Devtools jar should be excluded, or
|
||||
* {@code false} if not
|
||||
* @deprecated since 2.3.0 in favour of configuring a classpath that does not include
|
||||
* development-only dependencies
|
||||
*/
|
||||
@Deprecated
|
||||
void setExcludeDevtools(boolean excludeDevtools);
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class BootArchiveSupport {
|
||||
|
||||
private LaunchScriptConfiguration launchScript;
|
||||
|
||||
private boolean excludeDevtools = true;
|
||||
private boolean excludeDevtools = false;
|
||||
|
||||
BootArchiveSupport(String loaderMainClass, Spec<FileCopyDetails> librarySpec,
|
||||
Function<FileCopyDetails, ZipCompression> compressionResolver) {
|
||||
|
||||
Reference in New Issue
Block a user