|
26 | 26 | import org.gradle.api.Action;
|
27 | 27 | import org.gradle.api.Plugin;
|
28 | 28 | import org.gradle.api.Project;
|
| 29 | +import org.gradle.api.Task; |
29 | 30 | import org.gradle.api.file.FileCollection;
|
30 | 31 | import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;
|
31 | 32 | import org.gradle.api.plugins.ApplicationPlugin;
|
@@ -145,37 +146,49 @@ private void configureAdditionalMetadataLocations(Project project) {
|
145 | 146 | }
|
146 | 147 |
|
147 | 148 | private void configureAdditionalMetadataLocations(JavaCompile compile) {
|
148 |
| - compile.doFirst((task) -> { |
| 149 | + compile.doFirst(new AdditionalMetadataLocationsConfigurer()); |
| 150 | + } |
| 151 | + |
| 152 | + private static class AdditionalMetadataLocationsConfigurer implements Action<Task> { |
| 153 | + |
| 154 | + @Override |
| 155 | + public void execute(Task task) { |
| 156 | + if (!(task instanceof JavaCompile)) { |
| 157 | + return; |
| 158 | + } |
| 159 | + JavaCompile compile = (JavaCompile) task; |
149 | 160 | if (hasConfigurationProcessorOnClasspath(compile)) {
|
150 | 161 | findMatchingSourceSet(compile).ifPresent(
|
151 | 162 | (sourceSet) -> configureAdditionalMetadataLocations(compile,
|
152 | 163 | sourceSet));
|
153 | 164 | }
|
154 |
| - }); |
155 |
| - } |
156 |
| - |
157 |
| - private Optional<SourceSet> findMatchingSourceSet(JavaCompile compile) { |
158 |
| - return compile.getProject().getConvention().getPlugin(JavaPluginConvention.class) |
159 |
| - .getSourceSets().stream().filter((sourceSet) -> sourceSet |
160 |
| - .getCompileJavaTaskName().equals(compile.getName())) |
161 |
| - .findFirst(); |
162 |
| - } |
163 |
| - |
164 |
| - private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) { |
165 |
| - Set<File> files = (compile.getOptions().getAnnotationProcessorPath() != null) |
166 |
| - ? compile.getOptions().getAnnotationProcessorPath().getFiles() |
167 |
| - : compile.getClasspath().getFiles(); |
168 |
| - return files.stream().map(File::getName).anyMatch( |
169 |
| - (name) -> name.startsWith("spring-boot-configuration-processor")); |
170 |
| - } |
| 165 | + } |
| 166 | + |
| 167 | + private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) { |
| 168 | + Set<File> files = (compile.getOptions().getAnnotationProcessorPath() != null) |
| 169 | + ? compile.getOptions().getAnnotationProcessorPath().getFiles() |
| 170 | + : compile.getClasspath().getFiles(); |
| 171 | + return files.stream().map(File::getName).anyMatch( |
| 172 | + (name) -> name.startsWith("spring-boot-configuration-processor")); |
| 173 | + } |
| 174 | + |
| 175 | + private Optional<SourceSet> findMatchingSourceSet(JavaCompile compile) { |
| 176 | + return compile |
| 177 | + .getProject().getConvention().getPlugin(JavaPluginConvention.class) |
| 178 | + .getSourceSets().stream().filter((sourceSet) -> sourceSet |
| 179 | + .getCompileJavaTaskName().equals(compile.getName())) |
| 180 | + .findFirst(); |
| 181 | + } |
| 182 | + |
| 183 | + private void configureAdditionalMetadataLocations(JavaCompile compile, |
| 184 | + SourceSet sourceSet) { |
| 185 | + String locations = StringUtils.collectionToCommaDelimitedString( |
| 186 | + sourceSet.getResources().getSrcDirs()); |
| 187 | + compile.getOptions().getCompilerArgs().add( |
| 188 | + "-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" |
| 189 | + + locations); |
| 190 | + } |
171 | 191 |
|
172 |
| - private void configureAdditionalMetadataLocations(JavaCompile compile, |
173 |
| - SourceSet sourceSet) { |
174 |
| - String locations = StringUtils |
175 |
| - .collectionToCommaDelimitedString(sourceSet.getResources().getSrcDirs()); |
176 |
| - compile.getOptions().getCompilerArgs().add( |
177 |
| - "-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" |
178 |
| - + locations); |
179 | 192 | }
|
180 | 193 |
|
181 | 194 | }
|
0 commit comments