diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index 2ab46db58e..b698ce9b12 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java @@ -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 { + private static final class AdditionalMetadataLocationsConfigurer implements Action { + + private final Set locations; + + private AdditionalMetadataLocationsConfigurer(Set 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 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)); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java index 6c06324d8e..9633fc1830 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java @@ -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; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle index 7ffcce40ab..e96ca9aa28 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.gradle @@ -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}" + } } } \ No newline at end of file