From 1973e342c977055be50bdef4634e2c49628ff32a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 14 Aug 2018 11:54:13 +0100 Subject: [PATCH] Do not use lambda for task action as it breaks up-to-date checks Due to gradle/gradle#5510, using a lambda for a task action breaks up-to-date checks in certain circumstances. This commit updates JavaPluginAction to use an inner-class in place of a lambda for the action that it adds to JavaCompile tasks. A test has not been added as it does not appear to be possible to reproduce it with a TestKit-based test. Closes gh-14054 --- .../boot/gradle/plugin/JavaPluginAction.java | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) 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 fae59a4136..4e86b3549c 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 @@ -26,6 +26,7 @@ import java.util.concurrent.Callable; import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.Task; import org.gradle.api.file.FileCollection; import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact; import org.gradle.api.plugins.ApplicationPlugin; @@ -145,37 +146,49 @@ final class JavaPluginAction implements PluginApplicationAction { } private void configureAdditionalMetadataLocations(JavaCompile compile) { - compile.doFirst((task) -> { + compile.doFirst(new AdditionalMetadataLocationsConfigurer()); + } + + private static class AdditionalMetadataLocationsConfigurer implements Action { + + @Override + public void execute(Task task) { + if (!(task instanceof JavaCompile)) { + return; + } + JavaCompile compile = (JavaCompile) task; if (hasConfigurationProcessorOnClasspath(compile)) { findMatchingSourceSet(compile).ifPresent( (sourceSet) -> configureAdditionalMetadataLocations(compile, sourceSet)); } - }); - } - - private Optional findMatchingSourceSet(JavaCompile compile) { - return compile.getProject().getConvention().getPlugin(JavaPluginConvention.class) - .getSourceSets().stream().filter((sourceSet) -> sourceSet - .getCompileJavaTaskName().equals(compile.getName())) - .findFirst(); - } - - private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) { - Set 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")); - } + } + + private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) { + Set 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")); + } + + 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()); + compile.getOptions().getCompilerArgs().add( + "-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" + + locations); + } - private void configureAdditionalMetadataLocations(JavaCompile compile, - SourceSet sourceSet) { - String locations = StringUtils - .collectionToCommaDelimitedString(sourceSet.getResources().getSrcDirs()); - compile.getOptions().getCompilerArgs().add( - "-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" - + locations); } }