Merge branch '2.7.x' into 3.0.x

This commit is contained in:
Phillip Webb
2023-02-21 23:15:40 -08:00
1890 changed files with 27173 additions and 21952 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,8 +91,9 @@ public class SpringBootExtension {
this::configureBuildInfoTask);
this.project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo));
bootBuildInfo.configure((buildInfo) -> buildInfo.getProperties().getArtifact()
.convention(this.project.provider(() -> determineArtifactBaseName())));
bootBuildInfo.configure((buildInfo) -> buildInfo.getProperties()
.getArtifact()
.convention(this.project.provider(() -> determineArtifactBaseName())));
});
if (configurer != null) {
bootBuildInfo.configure(configurer);
@@ -102,13 +103,18 @@ public class SpringBootExtension {
private void configureBuildInfoTask(BuildInfo task) {
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Generates a META-INF/build-info.properties file.");
task.getDestinationDir().convention(this.project.getLayout()
task.getDestinationDir()
.convention(this.project.getLayout()
.dir(this.project.provider(() -> new File(determineMainSourceSetResourcesOutputDir(), "META-INF"))));
}
private File determineMainSourceSetResourcesOutputDir() {
return this.project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir();
return this.project.getExtensions()
.getByType(JavaPluginExtension.class)
.getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
.getOutput()
.getResourcesDir();
}
private String determineArtifactBaseName() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,10 +49,10 @@ final class ApplicationPluginAction implements PluginApplicationAction {
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
Distribution distribution = distributions.create("boot");
distribution.getDistributionBaseName()
.convention((project.provider(() -> javaApplication.getApplicationName() + "-boot")));
TaskProvider<CreateStartScripts> bootStartScripts = project.getTasks().register("bootStartScripts",
CreateStartScripts.class,
(task) -> configureCreateStartScripts(project, javaApplication, distribution, task));
.convention((project.provider(() -> javaApplication.getApplicationName() + "-boot")));
TaskProvider<CreateStartScripts> bootStartScripts = project.getTasks()
.register("bootStartScripts", CreateStartScripts.class,
(task) -> configureCreateStartScripts(project, javaApplication, distribution, task));
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
binCopySpec.setFileMode(0755);
distribution.getContents().with(binCopySpec);
@@ -61,19 +61,19 @@ final class ApplicationPluginAction implements PluginApplicationAction {
private void configureCreateStartScripts(Project project, JavaApplication javaApplication,
Distribution distribution, CreateStartScripts createStartScripts) {
createStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) createStartScripts.getUnixStartScriptGenerator())
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
((TemplateBasedScriptGenerator) createStartScripts.getWindowsStartScriptGenerator())
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
project.getConfigurations().all((configuration) -> {
if ("bootArchives".equals(configuration.getName())) {
distribution.getContents().with(artifactFilesToLibCopySpec(project, configuration));
createStartScripts.setClasspath(configuration.getArtifacts().getFiles());
}
});
createStartScripts.getConventionMapping().map("outputDir",
() -> new File(project.getBuildDir(), "bootScripts"));
createStartScripts.getConventionMapping()
.map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
createStartScripts.getConventionMapping().map("applicationName", javaApplication::getApplicationName);
createStartScripts.getConventionMapping().map("defaultJvmOpts", javaApplication::getApplicationDefaultJvmArgs);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,8 +32,9 @@ final class DependencyManagementPluginAction implements PluginApplicationAction
@Override
public void execute(Project project) {
project.getExtensions().findByType(DependencyManagementExtension.class)
.imports((importsHandler) -> importsHandler.mavenBom(SpringBootPlugin.BOM_COORDINATES));
project.getExtensions()
.findByType(DependencyManagementExtension.class)
.imports((importsHandler) -> importsHandler.mavenBom(SpringBootPlugin.BOM_COORDINATES));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,36 +91,41 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void classifyJarTask(Project project) {
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class)
.configure((task) -> task.getArchiveClassifier().convention("plain"));
project.getTasks()
.named(JavaPlugin.JAR_TASK_NAME, Jar.class)
.configure((task) -> task.getArchiveClassifier().convention("plain"));
}
private void configureBuildTask(Project project) {
project.getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME)
.configure((task) -> task.dependsOn(this.singlePublishedArtifact));
project.getTasks()
.named(BasePlugin.ASSEMBLE_TASK_NAME)
.configure((task) -> task.dependsOn(this.singlePublishedArtifact));
}
private TaskProvider<ResolveMainClassName> configureResolveMainClassNameTask(Project project) {
return project.getTasks().register(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME,
ResolveMainClassName.class, (resolveMainClassName) -> {
ExtensionContainer extensions = project.getExtensions();
resolveMainClassName.setDescription("Resolves the name of the application's main class.");
resolveMainClassName.setGroup(BasePlugin.BUILD_GROUP);
Callable<FileCollection> classpath = () -> project.getExtensions()
.getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput();
resolveMainClassName.setClasspath(classpath);
resolveMainClassName.getConfiguredMainClassName().convention(project.provider(() -> {
String javaApplicationMainClass = getJavaApplicationMainClass(extensions);
if (javaApplicationMainClass != null) {
return javaApplicationMainClass;
}
SpringBootExtension springBootExtension = project.getExtensions()
return project.getTasks()
.register(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class,
(resolveMainClassName) -> {
ExtensionContainer extensions = project.getExtensions();
resolveMainClassName.setDescription("Resolves the name of the application's main class.");
resolveMainClassName.setGroup(BasePlugin.BUILD_GROUP);
Callable<FileCollection> classpath = () -> project.getExtensions()
.getByType(SourceSetContainer.class)
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
.getOutput();
resolveMainClassName.setClasspath(classpath);
resolveMainClassName.getConfiguredMainClassName().convention(project.provider(() -> {
String javaApplicationMainClass = getJavaApplicationMainClass(extensions);
if (javaApplicationMainClass != null) {
return javaApplicationMainClass;
}
SpringBootExtension springBootExtension = project.getExtensions()
.findByType(SpringBootExtension.class);
return springBootExtension.getMainClass().getOrNull();
}));
resolveMainClassName.getOutputFile()
return springBootExtension.getMainClass().getOrNull();
}));
resolveMainClassName.getOutputFile()
.set(project.getLayout().getBuildDirectory().file("resolvedMainClassName"));
});
});
}
private static String getJavaApplicationMainClass(ExtensionContainer extensions) {
@@ -134,24 +139,26 @@ final class JavaPluginAction implements PluginApplicationAction {
private TaskProvider<BootJar> configureBootJarTask(Project project,
TaskProvider<ResolveMainClassName> resolveMainClassName) {
SourceSet mainSourceSet = javaPluginExtension(project).getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
Configuration developmentOnly = project.getConfigurations()
.getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
.getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
Configuration productionRuntimeClasspath = project.getConfigurations()
.getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
.getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Callable<FileCollection> classpath = () -> mainSourceSet.getRuntimeClasspath()
.minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
.minus((developmentOnly.minus(productionRuntimeClasspath)))
.filter(new JarTypeFileSpec());
return project.getTasks().register(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class, (bootJar) -> {
bootJar.setDescription(
"Assembles an executable jar archive containing the main classes and their dependencies.");
bootJar.setGroup(BasePlugin.BUILD_GROUP);
bootJar.classpath(classpath);
Provider<String> manifestStartClass = project
.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
bootJar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
bootJar.getMainClass()
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
bootJar.getTargetJavaVersion()
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
});
}
@@ -169,7 +176,9 @@ final class JavaPluginAction implements PluginApplicationAction {
private void configureBootRunTask(Project project, TaskProvider<ResolveMainClassName> resolveMainClassName) {
Callable<FileCollection> classpath = () -> javaPluginExtension(project).getSourceSets()
.findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath().filter(new JarTypeFileSpec());
.findByName(SourceSet.MAIN_SOURCE_SET_NAME)
.getRuntimeClasspath()
.filter(new JarTypeFileSpec());
project.getTasks().register("bootRun", BootRun.class, (run) -> {
run.setDescription("Runs this project as a Spring Boot application.");
run.setGroup(ApplicationPlugin.APPLICATION_GROUP);
@@ -215,27 +224,32 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void configureAdditionalMetadataLocations(Project project) {
project.afterEvaluate((evaluated) -> evaluated.getTasks().withType(JavaCompile.class)
.configureEach(this::configureAdditionalMetadataLocations));
project.afterEvaluate((evaluated) -> evaluated.getTasks()
.withType(JavaCompile.class)
.configureEach(this::configureAdditionalMetadataLocations));
}
private void configureAdditionalMetadataLocations(JavaCompile compile) {
SourceSetContainer sourceSets = compile.getProject().getExtensions().getByType(JavaPluginExtension.class)
.getSourceSets();
sourceSets.stream().filter((candidate) -> candidate.getCompileJavaTaskName().equals(compile.getName()))
.map((match) -> match.getResources().getSrcDirs()).findFirst()
.ifPresent((locations) -> compile.doFirst(new AdditionalMetadataLocationsConfigurer(locations)));
SourceSetContainer sourceSets = compile.getProject()
.getExtensions()
.getByType(JavaPluginExtension.class)
.getSourceSets();
sourceSets.stream()
.filter((candidate) -> candidate.getCompileJavaTaskName().equals(compile.getName()))
.map((match) -> match.getResources().getSrcDirs())
.findFirst()
.ifPresent((locations) -> compile.doFirst(new AdditionalMetadataLocationsConfigurer(locations)));
}
private void configureDevelopmentOnlyConfiguration(Project project) {
Configuration developmentOnly = project.getConfigurations()
.create(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
.create(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
developmentOnly
.setDescription("Configuration for development-only dependencies such as Spring Boot's DevTools.");
.setDescription("Configuration for development-only dependencies such as Spring Boot's DevTools.");
Configuration runtimeClasspath = project.getConfigurations()
.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Configuration productionRuntimeClasspath = project.getConfigurations()
.create(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
.create(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
AttributeContainer attributes = productionRuntimeClasspath.getAttributes();
ObjectFactory objectFactory = project.getObjects();
attributes.attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
@@ -275,14 +289,16 @@ final class JavaPluginAction implements PluginApplicationAction {
private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) {
Set<File> files = (compile.getOptions().getAnnotationProcessorPath() != null)
? compile.getOptions().getAnnotationProcessorPath().getFiles() : compile.getClasspath().getFiles();
return files.stream().map(File::getName)
.anyMatch((name) -> name.startsWith("spring-boot-configuration-processor"));
return files.stream()
.map(File::getName)
.anyMatch((name) -> name.startsWith("spring-boot-configuration-processor"));
}
private void configureAdditionalMetadataLocations(JavaCompile compile) {
compile.getOptions().getCompilerArgs()
.add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
+ StringUtils.collectionToCommaDelimitedString(this.locations));
compile.getOptions()
.getCompilerArgs()
.add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
+ StringUtils.collectionToCommaDelimitedString(this.locations));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,8 +47,9 @@ class KotlinPluginAction implements PluginApplicationAction {
}
private void enableJavaParametersOption(Project project) {
project.getTasks().withType(KotlinCompile.class)
.configureEach((compile) -> compile.getKotlinOptions().setJavaParameters(true));
project.getTasks()
.withType(KotlinCompile.class)
.configureEach((compile) -> compile.getKotlinOptions().setJavaParameters(true));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,15 +70,16 @@ class NativeImagePluginAction implements PluginApplicationAction {
private void configureMainNativeBinaryClasspath(Project project, SourceSetContainer sourceSets,
GraalVMExtension graalVmExtension) {
FileCollection runtimeClasspath = sourceSets.getByName(SpringBootAotPlugin.AOT_SOURCE_SET_NAME)
.getRuntimeClasspath();
.getRuntimeClasspath();
graalVmExtension.getBinaries().getByName(NativeImagePlugin.NATIVE_MAIN_EXTENSION).classpath(runtimeClasspath);
Configuration nativeImageClasspath = project.getConfigurations().getByName("nativeImageClasspath");
nativeImageClasspath.setExtendsFrom(removeDevelopmentOnly(nativeImageClasspath.getExtendsFrom()));
}
private Iterable<Configuration> removeDevelopmentOnly(Set<Configuration> configurations) {
return configurations.stream().filter(this::isNotDevelopmentOnly)
.collect(Collectors.toCollection(LinkedHashSet::new));
return configurations.stream()
.filter(this::isNotDevelopmentOnly)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
private boolean isNotDevelopmentOnly(Configuration configuration) {
@@ -88,7 +89,7 @@ class NativeImagePluginAction implements PluginApplicationAction {
private void configureTestNativeBinaryClasspath(Project project, SourceSetContainer sourceSets,
GraalVMExtension graalVmExtension) {
FileCollection runtimeClasspath = sourceSets.getByName(SpringBootAotPlugin.AOT_TEST_SOURCE_SET_NAME)
.getRuntimeClasspath();
.getRuntimeClasspath();
graalVmExtension.getBinaries().getByName(NativeImagePlugin.NATIVE_TEST_EXTENSION).classpath(runtimeClasspath);
}
@@ -109,21 +110,23 @@ class NativeImagePluginAction implements PluginApplicationAction {
private void configureGraalVmReachabilityExtension(GraalVMExtension graalVmExtension) {
GraalVMReachabilityMetadataRepositoryExtension extension = ((ExtensionAware) graalVmExtension).getExtensions()
.getByType(GraalVMReachabilityMetadataRepositoryExtension.class);
.getByType(GraalVMReachabilityMetadataRepositoryExtension.class);
extension.getEnabled().set(true);
}
private void copyReachabilityMetadataToBootJar(Project project) {
project.getTasks().named(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class)
.configure((bootJar) -> bootJar.from(project.getTasks().named("collectReachabilityMetadata")));
project.getTasks()
.named(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class)
.configure((bootJar) -> bootJar.from(project.getTasks().named("collectReachabilityMetadata")));
}
private void configureBootBuildImageToProduceANativeImage(Project project) {
project.getTasks().named(SpringBootPlugin.BOOT_BUILD_IMAGE_TASK_NAME, BootBuildImage.class)
.configure((bootBuildImage) -> {
bootBuildImage.getBuilder().convention("paketobuildpacks/builder:tiny");
bootBuildImage.getEnvironment().put("BP_NATIVE_IMAGE", "true");
});
project.getTasks()
.named(SpringBootPlugin.BOOT_BUILD_IMAGE_TASK_NAME, BootBuildImage.class)
.configure((bootBuildImage) -> {
bootBuildImage.getBuilder().convention("paketobuildpacks/builder:tiny");
bootBuildImage.getEnvironment().put("BP_NATIVE_IMAGE", "true");
});
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -130,8 +130,13 @@ public class ResolveMainClassName extends DefaultTask {
if (configuredMainClass != null) {
return configuredMainClass;
}
return getClasspath().filter(File::isDirectory).getFiles().stream().map(this::findMainClass)
.filter(Objects::nonNull).findFirst().orElse("");
return getClasspath().filter(File::isDirectory)
.getFiles()
.stream()
.map(this::findMainClass)
.filter(Objects::nonNull)
.findFirst()
.orElse("");
}
private String findMainClass(File file) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,17 +90,18 @@ public class SpringBootAotPlugin implements Plugin<Project> {
SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
return sourceSets.create(newSourceSetName, (sourceSet) -> {
existingSourceSet.setRuntimeClasspath(existingSourceSet.getRuntimeClasspath().plus(sourceSet.getOutput()));
project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName())
.attributes((attributes) -> {
configureClassesAndResourcesLibraryElementsAttribute(project, attributes);
configureJavaRuntimeUsageAttribute(project, attributes);
});
project.getConfigurations()
.getByName(sourceSet.getCompileClasspathConfigurationName())
.attributes((attributes) -> {
configureClassesAndResourcesLibraryElementsAttribute(project, attributes);
configureJavaRuntimeUsageAttribute(project, attributes);
});
});
}
private void configureClassesAndResourcesLibraryElementsAttribute(Project project, AttributeContainer attributes) {
LibraryElements classesAndResources = project.getObjects().named(LibraryElements.class,
LibraryElements.CLASSES_AND_RESOURCES);
LibraryElements classesAndResources = project.getObjects()
.named(LibraryElements.class, LibraryElements.CLASSES_AND_RESOURCES);
attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, classesAndResources);
}
@@ -111,21 +112,22 @@ public class SpringBootAotPlugin implements Plugin<Project> {
private void registerProcessAotTask(Project project, SourceSet aotSourceSet, SourceSet mainSourceSet) {
TaskProvider<ResolveMainClassName> resolveMainClassName = project.getTasks()
.named(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class);
.named(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class);
Configuration aotClasspath = createAotProcessingClasspath(project, PROCESS_AOT_TASK_NAME, mainSourceSet);
project.getDependencies().add(aotClasspath.getName(), project.files(mainSourceSet.getOutput()));
Configuration compileClasspath = project.getConfigurations()
.getByName(aotSourceSet.getCompileClasspathConfigurationName());
.getByName(aotSourceSet.getCompileClasspathConfigurationName());
compileClasspath.extendsFrom(aotClasspath);
Provider<Directory> resourcesOutput = project.getLayout().getBuildDirectory()
.dir("generated/" + aotSourceSet.getName() + "Resources");
TaskProvider<ProcessAot> processAot = project.getTasks().register(PROCESS_AOT_TASK_NAME, ProcessAot.class,
(task) -> {
configureAotTask(project, aotSourceSet, task, mainSourceSet, resourcesOutput);
task.getApplicationMainClass()
.set(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName));
task.setClasspath(aotClasspath);
});
Provider<Directory> resourcesOutput = project.getLayout()
.getBuildDirectory()
.dir("generated/" + aotSourceSet.getName() + "Resources");
TaskProvider<ProcessAot> processAot = project.getTasks()
.register(PROCESS_AOT_TASK_NAME, ProcessAot.class, (task) -> {
configureAotTask(project, aotSourceSet, task, mainSourceSet, resourcesOutput);
task.getApplicationMainClass()
.set(resolveMainClassName.flatMap(ResolveMainClassName::readMainClassName));
task.setClasspath(aotClasspath);
});
aotSourceSet.getJava().srcDir(processAot.map(ProcessAot::getSourcesOutput));
aotSourceSet.getResources().srcDir(resourcesOutput);
ConfigurableFileCollection classesOutputFiles = project.files(processAot.map(ProcessAot::getClassesOutput));
@@ -137,10 +139,10 @@ public class SpringBootAotPlugin implements Plugin<Project> {
private void configureAotTask(Project project, SourceSet sourceSet, AbstractAot task, SourceSet inputSourceSet,
Provider<Directory> resourcesOutput) {
task.getSourcesOutput()
.set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Sources"));
.set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Sources"));
task.getResourcesOutput().set(resourcesOutput);
task.getClassesOutput()
.set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Classes"));
.set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Classes"));
task.getGroupId().set(project.provider(() -> String.valueOf(project.getGroup())));
task.getArtifactId().set(project.provider(() -> project.getName()));
}
@@ -148,7 +150,7 @@ public class SpringBootAotPlugin implements Plugin<Project> {
@SuppressWarnings("unchecked")
private Configuration createAotProcessingClasspath(Project project, String taskName, SourceSet inputSourceSet) {
Configuration base = project.getConfigurations()
.getByName(inputSourceSet.getRuntimeClasspathConfigurationName());
.getByName(inputSourceSet.getRuntimeClasspathConfigurationName());
Configuration aotClasspath = project.getConfigurations().create(taskName + "Classpath", (classpath) -> {
classpath.setCanBeConsumed(false);
classpath.setCanBeResolved(true);
@@ -166,8 +168,9 @@ public class SpringBootAotPlugin implements Plugin<Project> {
private void configureDependsOn(Project project, SourceSet aotSourceSet,
TaskProvider<? extends AbstractAot> processAot) {
project.getTasks().named(aotSourceSet.getProcessResourcesTaskName())
.configure((processResources) -> processResources.dependsOn(processAot));
project.getTasks()
.named(aotSourceSet.getProcessResourcesTaskName())
.configure((processResources) -> processResources.dependsOn(processAot));
}
private void registerProcessTestAotTask(Project project, SourceSet mainSourceSet, SourceSet aotTestSourceSet,
@@ -175,22 +178,23 @@ public class SpringBootAotPlugin implements Plugin<Project> {
Configuration aotClasspath = createAotProcessingClasspath(project, PROCESS_TEST_AOT_TASK_NAME, testSourceSet);
addJUnitPlatformLauncherDependency(project, aotClasspath);
Configuration compileClasspath = project.getConfigurations()
.getByName(aotTestSourceSet.getCompileClasspathConfigurationName());
.getByName(aotTestSourceSet.getCompileClasspathConfigurationName());
compileClasspath.extendsFrom(aotClasspath);
Provider<Directory> resourcesOutput = project.getLayout().getBuildDirectory()
.dir("generated/" + aotTestSourceSet.getName() + "Resources");
TaskProvider<ProcessTestAot> processTestAot = project.getTasks().register(PROCESS_TEST_AOT_TASK_NAME,
ProcessTestAot.class, (task) -> {
configureAotTask(project, aotTestSourceSet, task, testSourceSet, resourcesOutput);
task.setClasspath(aotClasspath);
task.setClasspathRoots(testSourceSet.getOutput());
});
Provider<Directory> resourcesOutput = project.getLayout()
.getBuildDirectory()
.dir("generated/" + aotTestSourceSet.getName() + "Resources");
TaskProvider<ProcessTestAot> processTestAot = project.getTasks()
.register(PROCESS_TEST_AOT_TASK_NAME, ProcessTestAot.class, (task) -> {
configureAotTask(project, aotTestSourceSet, task, testSourceSet, resourcesOutput);
task.setClasspath(aotClasspath);
task.setClasspathRoots(testSourceSet.getOutput());
});
aotTestSourceSet.getJava().srcDir(processTestAot.map(ProcessTestAot::getSourcesOutput));
aotTestSourceSet.getResources().srcDir(resourcesOutput);
project.getDependencies().add(aotClasspath.getName(), project.files(mainSourceSet.getOutput()));
project.getDependencies().add(aotClasspath.getName(), project.files(testSourceSet.getOutput()));
ConfigurableFileCollection classesOutputFiles = project
.files(processTestAot.map(ProcessTestAot::getClassesOutput));
.files(processTestAot.map(ProcessTestAot::getClassesOutput));
testSourceSet.setRuntimeClasspath(testSourceSet.getRuntimeClasspath().plus(classesOutputFiles));
project.getDependencies().add(aotTestSourceSet.getImplementationConfigurationName(), classesOutputFiles);
configureDependsOn(project, aotTestSourceSet, processTestAot);
@@ -199,7 +203,7 @@ public class SpringBootAotPlugin implements Plugin<Project> {
private void addJUnitPlatformLauncherDependency(Project project, Configuration configuration) {
DependencyHandler dependencyHandler = project.getDependencies();
Dependency springBootDependencies = dependencyHandler
.create(dependencyHandler.platform(SpringBootPlugin.BOM_COORDINATES));
.create(dependencyHandler.platform(SpringBootPlugin.BOM_COORDINATES));
DependencySet dependencies = configuration.getDependencies();
dependencies.add(springBootDependencies);
dependencies.add(dependencyHandler.create("org.junit.platform:junit-platform-launcher"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,36 +64,40 @@ class WarPluginAction implements PluginApplicationAction {
}
private void classifyWarTask(Project project) {
project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class)
.configure((war) -> war.getArchiveClassifier().convention("plain"));
project.getTasks()
.named(WarPlugin.WAR_TASK_NAME, War.class)
.configure((war) -> war.getArchiveClassifier().convention("plain"));
}
private TaskProvider<BootWar> configureBootWarTask(Project project) {
Configuration developmentOnly = project.getConfigurations()
.getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
.getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
Configuration productionRuntimeClasspath = project.getConfigurations()
.getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Callable<FileCollection> classpath = () -> project.getExtensions().getByType(SourceSetContainer.class)
.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath()
.minus(providedRuntimeConfiguration(project)).minus((developmentOnly.minus(productionRuntimeClasspath)))
.filter(new JarTypeFileSpec());
.getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Callable<FileCollection> classpath = () -> project.getExtensions()
.getByType(SourceSetContainer.class)
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
.getRuntimeClasspath()
.minus(providedRuntimeConfiguration(project))
.minus((developmentOnly.minus(productionRuntimeClasspath)))
.filter(new JarTypeFileSpec());
TaskProvider<ResolveMainClassName> resolveMainClassName = project.getTasks()
.named(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class);
TaskProvider<BootWar> bootWarProvider = project.getTasks().register(SpringBootPlugin.BOOT_WAR_TASK_NAME,
BootWar.class, (bootWar) -> {
bootWar.setGroup(BasePlugin.BUILD_GROUP);
bootWar.setDescription("Assembles an executable war archive containing webapp"
+ " content, and the main classes and their dependencies.");
bootWar.providedClasspath(providedRuntimeConfiguration(project));
bootWar.setClasspath(classpath);
Provider<String> manifestStartClass = project
.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
bootWar.getMainClass()
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
bootWar.getTargetJavaVersion()
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
});
.named(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class);
TaskProvider<BootWar> bootWarProvider = project.getTasks()
.register(SpringBootPlugin.BOOT_WAR_TASK_NAME, BootWar.class, (bootWar) -> {
bootWar.setGroup(BasePlugin.BUILD_GROUP);
bootWar.setDescription("Assembles an executable war archive containing webapp"
+ " content, and the main classes and their dependencies.");
bootWar.providedClasspath(providedRuntimeConfiguration(project));
bootWar.setClasspath(classpath);
Provider<String> manifestStartClass = project
.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
bootWar.getMainClass()
.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
? manifestStartClass : resolveMainClassName.get().readMainClassName()));
bootWar.getTargetJavaVersion()
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
});
bootWarProvider.map(War::getClasspath);
return bootWarProvider;
}
@@ -104,8 +108,9 @@ class WarPluginAction implements PluginApplicationAction {
}
private void configureBootBuildImageTask(Project project, TaskProvider<BootWar> bootWar) {
project.getTasks().named(SpringBootPlugin.BOOT_BUILD_IMAGE_TASK_NAME, BootBuildImage.class)
.configure((buildImage) -> buildImage.getArchiveFile().set(bootWar.get().getArchiveFile()));
project.getTasks()
.named(SpringBootPlugin.BOOT_BUILD_IMAGE_TASK_NAME, BootBuildImage.class)
.configure((buildImage) -> buildImage.getArchiveFile().set(bootWar.get().getArchiveFile()));
}
private void configureArtifactPublication(TaskProvider<BootWar> bootWar) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,8 +78,11 @@ public class ProcessTestAot extends AbstractAot {
@TaskAction
public void exec() {
List<String> args = new ArrayList<>();
args.add(getClasspathRoots().getFiles().stream().filter(File::exists).map(File::getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator)));
args.add(getClasspathRoots().getFiles()
.stream()
.filter(File::exists)
.map(File::getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator)));
args.addAll(processorArgs());
setArgs(args);
super.exec();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,7 +71,7 @@ public abstract class BuildInfo extends DefaultTask {
this.properties.getNameIfNotExcluded(), this.properties.getTimeIfNotExcluded(),
this.properties.getAdditionalIfNotExcluded());
new BuildPropertiesWriter(new File(getDestinationDir().get().getAsFile(), "build-info.properties"))
.writeBuildProperties(details);
.writeBuildProperties(details);
}
catch (IOException ex) {
throw new TaskExecutionException(this, ex);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public abstract class BuildInfoProperties implements Serializable {
getGroup().convention(project.provider(() -> project.getGroup().toString()));
getVersion().convention(project.provider(() -> project.getVersion().toString()));
getArtifact()
.convention(project.provider(() -> project.findProperty("archivesBaseName")).map(Object::toString));
.convention(project.provider(() -> project.findProperty("archivesBaseName")).map(Object::toString));
getName().convention(project.provider(project::getName));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,8 +78,9 @@ public abstract class BootBuildImage extends DefaultTask {
public BootBuildImage() {
this.projectName = getProject().getName();
Project project = getProject();
Property<String> projectVersion = project.getObjects().property(String.class)
.convention(project.provider(() -> project.getVersion().toString()));
Property<String> projectVersion = project.getObjects()
.property(String.class)
.convention(project.provider(() -> project.getVersion().toString()));
getImageName().convention(project.provider(() -> {
ImageName imageName = ImageName.of(this.projectName);
if ("unspecified".equals(projectVersion.get())) {

View File

@@ -165,7 +165,7 @@ public abstract class BootWar extends War implements BootArchive {
public void providedClasspath(Object... classpath) {
FileCollection existingClasspath = this.providedClasspath;
this.providedClasspath = getProject()
.files((existingClasspath != null) ? existingClasspath : Collections.emptyList(), classpath);
.files((existingClasspath != null) ? existingClasspath : Collections.emptyList(), classpath);
}
/**

View File

@@ -74,11 +74,11 @@ import org.springframework.util.StringUtils;
class BootZipCopyAction implements CopyAction {
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0)
.getTimeInMillis();
.getTimeInMillis();
private static final Pattern REACHABILITY_METADATA_PROPERTIES_LOCATION_PATTERN = Pattern
.compile(ReachabilityMetadataProperties.REACHABILITY_METADATA_PROPERTIES_LOCATION_TEMPLATE.formatted(".*",
".*", ".*"));
.compile(ReachabilityMetadataProperties.REACHABILITY_METADATA_PROPERTIES_LOCATION_TEMPLATE.formatted(".*", ".*",
".*"));
private final File output;
@@ -352,14 +352,14 @@ class BootZipCopyAction implements CopyAction {
Set<String> excludes = new LinkedHashSet<>();
for (Map.Entry<String, FileCopyDetails> entry : this.writtenLibraries.entrySet()) {
DependencyDescriptor descriptor = BootZipCopyAction.this.resolvedDependencies
.find(entry.getValue().getFile());
.find(entry.getValue().getFile());
LibraryCoordinates coordinates = (descriptor != null) ? descriptor.getCoordinates() : null;
FileCopyDetails propertiesFile = (coordinates != null) ? this.reachabilityMetadataProperties
.get(ReachabilityMetadataProperties.getLocation(coordinates)) : null;
.get(ReachabilityMetadataProperties.getLocation(coordinates)) : null;
if (propertiesFile != null) {
try (InputStream inputStream = propertiesFile.open()) {
ReachabilityMetadataProperties properties = ReachabilityMetadataProperties
.fromInputStream(inputStream);
.fromInputStream(inputStream);
if (properties.isOverridden()) {
excludes.add(entry.getKey());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -309,13 +309,15 @@ public abstract class LayeredSpec {
ContentSelector<Library> asLibrarySelector(Function<String, ContentFilter<Library>> filterFactory) {
Layer layer = new Layer(getIntoLayer());
List<ContentFilter<Library>> includeFilters = getIncludes().stream().map(filterFactory)
.collect(Collectors.toCollection(ArrayList::new));
List<ContentFilter<Library>> includeFilters = getIncludes().stream()
.map(filterFactory)
.collect(Collectors.toCollection(ArrayList::new));
if (this.includeProjectDependencies) {
includeFilters.add(Library::isLocal);
}
List<ContentFilter<Library>> excludeFilters = getExcludes().stream().map(filterFactory)
.collect(Collectors.toCollection(ArrayList::new));
List<ContentFilter<Library>> excludeFilters = getExcludes().stream()
.map(filterFactory)
.collect(Collectors.toCollection(ArrayList::new));
if (this.excludeProjectDependencies) {
excludeFilters.add(Library::isLocal);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,8 +50,11 @@ class ResolvedDependencies {
}
void processConfiguration(Project project, Configuration configuration) {
Set<String> localProjectIds = project.getRootProject().getAllprojects().stream().map(this::projectId)
.collect(Collectors.toSet());
Set<String> localProjectIds = project.getRootProject()
.getAllprojects()
.stream()
.map(this::projectId)
.collect(Collectors.toSet());
this.configurationDependencies.put(configuration,
new ResolvedConfigurationDependencies(localProjectIds, configuration.getResolvedConfiguration()));
}
@@ -83,7 +86,7 @@ class ResolvedDependencies {
for (ResolvedArtifact resolvedArtifact : lenientConfiguration.getArtifacts()) {
ModuleVersionIdentifier id = resolvedArtifact.getModuleVersion().getId();
boolean projectDependency = projectDependencyIds
.contains(id.getGroup() + ":" + id.getName() + ":" + id.getVersion());
.contains(id.getGroup() + ":" + id.getName() + ":" + id.getVersion());
this.dependencies.put(resolvedArtifact.getFile(), new DependencyDescriptor(
new ModuleVersionIdentifierLibraryCoordinates(id), projectDependency));
}