Merge branch '2.4.x' into 2.5.x

Closes gh-26997
pull/27157/head
Andy Wilkinson 3 years ago
commit 8405df10b8

@ -19,7 +19,6 @@ package org.springframework.boot.gradle.plugin;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.gradle.api.Action;
@ -41,6 +40,7 @@ import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.compile.JavaCompile;
@ -195,7 +195,11 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void configureAdditionalMetadataLocations(JavaCompile compile) {
compile.doFirst(new AdditionalMetadataLocationsConfigurer());
SourceSetContainer sourceSets = compile.getProject().getConvention().getPlugin(JavaPluginConvention.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) {
@ -225,7 +229,13 @@ final class JavaPluginAction implements PluginApplicationAction {
* inner-class rather than a lambda due to
* https://github.com/gradle/gradle/issues/5510.
*/
private static class AdditionalMetadataLocationsConfigurer implements Action<Task> {
private static final class AdditionalMetadataLocationsConfigurer implements Action<Task> {
private final Set<File> locations;
private AdditionalMetadataLocationsConfigurer(Set<File> locations) {
this.locations = locations;
}
@Override
public void execute(Task task) {
@ -234,8 +244,7 @@ final class JavaPluginAction implements PluginApplicationAction {
}
JavaCompile compile = (JavaCompile) task;
if (hasConfigurationProcessorOnClasspath(compile)) {
findMatchingSourceSet(compile)
.ifPresent((sourceSet) -> configureAdditionalMetadataLocations(compile, sourceSet));
configureAdditionalMetadataLocations(compile);
}
}
@ -246,15 +255,10 @@ final class JavaPluginAction implements PluginApplicationAction {
.anyMatch((name) -> name.startsWith("spring-boot-configuration-processor"));
}
private Optional<SourceSet> findMatchingSourceSet(JavaCompile compile) {
return compile.getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
.filter((sourceSet) -> sourceSet.getCompileJavaTaskName().equals(compile.getName())).findFirst();
}
private void configureAdditionalMetadataLocations(JavaCompile compile, SourceSet sourceSet) {
String locations = StringUtils.collectionToCommaDelimitedString(sourceSet.getResources().getSrcDirs());
private void configureAdditionalMetadataLocations(JavaCompile compile) {
compile.getOptions().getCompilerArgs()
.add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" + locations);
.add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
+ StringUtils.collectionToCommaDelimitedString(this.locations));
}
}

@ -31,11 +31,11 @@ import org.springframework.boot.gradle.testkit.GradleBuild;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link WarPluginAction}.
* Integration tests for {@link JavaPluginAction}.
*
* @author Andy Wilkinson
*/
@GradleCompatibility
@GradleCompatibility(configurationCache = true)
class JavaPluginActionIntegrationTests {
GradleBuild gradleBuild;

@ -37,9 +37,13 @@ task('configurationAttributes') {
}
task('configurationResolvabilityAndConsumability') {
doFirst {
def configuration = configurations.findByName(configurationName)
println "canBeResolved: ${configuration.canBeResolved}"
println "canBeConsumed: ${configuration.canBeConsumed}"
if (project.hasProperty("configurationName")) {
Configuration configuration = configurations.findByName(configurationName)
def canBeResolved = configuration.canBeResolved
def canBeConsumed = configuration.canBeConsumed
doFirst {
println "canBeResolved: ${canBeResolved}"
println "canBeConsumed: ${canBeConsumed}"
}
}
}
Loading…
Cancel
Save