1616
1717package io .spring .start .site .extension .build .maven ;
1818
19- import java .util .List ;
19+ import java .util .LinkedHashMap ;
20+ import java .util .Map ;
21+ import java .util .Set ;
2022
2123import io .spring .initializr .generator .buildsystem .Dependency ;
2224import io .spring .initializr .generator .buildsystem .maven .MavenBuild ;
3234 */
3335class RegisterAnnotationProcessorsBuildCustomizer implements BuildCustomizer <MavenBuild > {
3436
37+ /**
38+ * Some annotation processors must stay on the compile classpath, so that users can
39+ * use classes from them. Those dependencies are both annotation processors and
40+ * libraries.
41+ */
42+ private static final Set <String > ANNOTATION_PROCESSORS_ON_COMPILE_CLASSPATH = Set .of ("lombok" );
43+
3544 private final InitializrMetadata metadata ;
3645
3746 private final ProjectDescription projectDescription ;
@@ -46,18 +55,28 @@ public void customize(MavenBuild build) {
4655 if (!isJava ()) {
4756 return ;
4857 }
49- List <Dependency > annotationProcessors = build .dependencies ()
50- .ids ()
51- .filter (this ::isAnnotationProcessor )
52- .map ((id ) -> build .dependencies ().get (id ))
53- .toList ();
58+ Map <String , Dependency > annotationProcessors = getAnnotationProcessors (build );
5459 if (annotationProcessors .isEmpty ()) {
5560 return ;
5661 }
62+ configureOnMavenCompilerPlugin (build , annotationProcessors );
63+ removeFromDependencies (build , annotationProcessors );
64+ }
65+
66+ private Map <String , Dependency > getAnnotationProcessors (MavenBuild build ) {
67+ Map <String , Dependency > annotationProcessors = new LinkedHashMap <>();
68+ build .dependencies ()
69+ .ids ()
70+ .filter (this ::isAnnotationProcessor )
71+ .forEach ((id ) -> annotationProcessors .put (id , build .dependencies ().get (id )));
72+ return annotationProcessors ;
73+ }
74+
75+ private void configureOnMavenCompilerPlugin (MavenBuild build , Map <String , Dependency > annotationProcessors ) {
5776 build .plugins ().add ("org.apache.maven.plugins" , "maven-compiler-plugin" , (plugin ) -> {
5877 plugin .configuration ((configuration ) -> {
5978 configuration .add ("annotationProcessorPaths" , (annotationProcessorPaths ) -> {
60- for (Dependency annotationProcessor : annotationProcessors ) {
79+ for (Dependency annotationProcessor : annotationProcessors . values () ) {
6180 annotationProcessorPaths .add ("path" , (path ) -> {
6281 path .add ("groupId" , annotationProcessor .getGroupId ());
6382 path .add ("artifactId" , annotationProcessor .getArtifactId ());
@@ -67,7 +86,14 @@ public void customize(MavenBuild build) {
6786 });
6887 });
6988 });
89+ }
7090
91+ private void removeFromDependencies (MavenBuild build , Map <String , Dependency > annotationProcessors ) {
92+ annotationProcessors .keySet ().forEach ((id ) -> {
93+ if (!ANNOTATION_PROCESSORS_ON_COMPILE_CLASSPATH .contains (id )) {
94+ build .dependencies ().remove (id );
95+ }
96+ });
7197 }
7298
7399 private boolean isAnnotationProcessor (String id ) {
0 commit comments