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
This commit is contained in:
parent
da1858f620
commit
1973e342c9
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.Callable;
|
||||||
import org.gradle.api.Action;
|
import org.gradle.api.Action;
|
||||||
import org.gradle.api.Plugin;
|
import org.gradle.api.Plugin;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
import org.gradle.api.Task;
|
||||||
import org.gradle.api.file.FileCollection;
|
import org.gradle.api.file.FileCollection;
|
||||||
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
|
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
|
||||||
import org.gradle.api.plugins.ApplicationPlugin;
|
import org.gradle.api.plugins.ApplicationPlugin;
|
||||||
|
|
@ -145,20 +146,22 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureAdditionalMetadataLocations(JavaCompile compile) {
|
private void configureAdditionalMetadataLocations(JavaCompile compile) {
|
||||||
compile.doFirst((task) -> {
|
compile.doFirst(new AdditionalMetadataLocationsConfigurer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class AdditionalMetadataLocationsConfigurer implements Action<Task> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Task task) {
|
||||||
|
if (!(task instanceof JavaCompile)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JavaCompile compile = (JavaCompile) task;
|
||||||
if (hasConfigurationProcessorOnClasspath(compile)) {
|
if (hasConfigurationProcessorOnClasspath(compile)) {
|
||||||
findMatchingSourceSet(compile).ifPresent(
|
findMatchingSourceSet(compile).ifPresent(
|
||||||
(sourceSet) -> configureAdditionalMetadataLocations(compile,
|
(sourceSet) -> configureAdditionalMetadataLocations(compile,
|
||||||
sourceSet));
|
sourceSet));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<SourceSet> 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) {
|
private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) {
|
||||||
|
|
@ -169,13 +172,23 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||||
(name) -> name.startsWith("spring-boot-configuration-processor"));
|
(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,
|
private void configureAdditionalMetadataLocations(JavaCompile compile,
|
||||||
SourceSet sourceSet) {
|
SourceSet sourceSet) {
|
||||||
String locations = StringUtils
|
String locations = StringUtils.collectionToCommaDelimitedString(
|
||||||
.collectionToCommaDelimitedString(sourceSet.getResources().getSrcDirs());
|
sourceSet.getResources().getSrcDirs());
|
||||||
compile.getOptions().getCompilerArgs().add(
|
compile.getOptions().getCompilerArgs().add(
|
||||||
"-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
|
"-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
|
||||||
+ locations);
|
+ locations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue