@ -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.compile.JavaCompile ;
import org.gradle.jvm.toolchain.JavaToolchainService ;
@ -200,7 +200,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 ) {
@ -230,7 +234,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 ) {
@ -239,8 +249,7 @@ final class JavaPluginAction implements PluginApplicationAction {
}
JavaCompile compile = ( JavaCompile ) task ;
if ( hasConfigurationProcessorOnClasspath ( compile ) ) {
findMatchingSourceSet ( compile )
. ifPresent ( ( sourceSet ) - > configureAdditionalMetadataLocations ( compile , sourceSet ) ) ;
configureAdditionalMetadataLocations ( compile ) ;
}
}
@ -251,15 +260,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 ) ) ;
}
}