Skip to content

Commit 4763123

Browse files
committed
Recommend using Maven's <annotationProcessorPaths>
Closes gh-43329
1 parent 13c9f68 commit 4763123

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/developing-auto-configuration.adoc

+7-18
Original file line numberDiff line numberDiff line change
@@ -283,34 +283,23 @@ If you do it that way, the library is not provided and, by default, Spring Boot
283283
Spring Boot uses an annotation processor to collect the conditions on auto-configurations in a metadata file (`META-INF/spring-autoconfigure-metadata.properties`).
284284
If that file is present, it is used to eagerly filter auto-configurations that do not match, which will improve startup time.
285285

286-
When building with Maven, it is recommended to add the following dependency in a module that contains auto-configurations:
287-
288-
[source,xml]
289-
----
290-
<dependency>
291-
<groupId>org.springframework.boot</groupId>
292-
<artifactId>spring-boot-autoconfigure-processor</artifactId>
293-
<optional>true</optional>
294-
</dependency>
295-
----
296-
297-
If you have defined auto-configurations directly in your application, make sure to configure the `spring-boot-maven-plugin` to prevent the `repackage` goal from adding the dependency into the uber jar:
286+
When building with Maven, configure the compiler plugin (3.12.0 or later) to add `spring-boot-autoconfigure-processor` to the annotation processor paths:
298287

299288
[source,xml]
300289
----
301290
<project>
302291
<build>
303292
<plugins>
304293
<plugin>
305-
<groupId>org.springframework.boot</groupId>
306-
<artifactId>spring-boot-maven-plugin</artifactId>
294+
<groupId>org.apache.maven.plugins</groupId>
295+
<artifactId>maven-compiler-plugin</artifactId>
307296
<configuration>
308-
<excludes>
309-
<exclude>
297+
<annotationProcessorPaths>
298+
<path>
310299
<groupId>org.springframework.boot</groupId>
311300
<artifactId>spring-boot-autoconfigure-processor</artifactId>
312-
</exclude>
313-
</excludes>
301+
</path>
302+
</annotationProcessorPaths>
314303
</configuration>
315304
</plugin>
316305
</plugins>

spring-boot-project/spring-boot-docs/src/docs/antora/modules/specification/pages/configuration-metadata/annotation-processor.adoc

+22-11
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,31 @@ The jar includes a Java annotation processor which is invoked as your project is
99
[[appendix.configuration-metadata.annotation-processor.configuring]]
1010
== Configuring the Annotation Processor
1111

12-
To use the processor, include a dependency on `spring-boot-configuration-processor`.
13-
14-
With Maven the dependency should be declared as optional, as shown in the following example:
12+
When building with Maven, configure the compiler plugin (3.12.0 or later) to add `spring-boot-configuration-processor` to the annotation processor paths:
1513

1614
[source,xml]
1715
----
18-
<dependency>
19-
<groupId>org.springframework.boot</groupId>
20-
<artifactId>spring-boot-configuration-processor</artifactId>
21-
<optional>true</optional>
22-
</dependency>
16+
<project>
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-compiler-plugin</artifactId>
22+
<configuration>
23+
<annotationProcessorPaths>
24+
<path>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-configuration-processor</artifactId>
27+
</path>
28+
</annotationProcessorPaths>
29+
</configuration>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
2334
----
2435

25-
With Gradle, the dependency should be declared in the `annotationProcessor` configuration, as shown in the following example:
36+
With Gradle, a dependency should be declared in the `annotationProcessor` configuration, as shown in the following example:
2637

2738
[source,gradle]
2839
----
@@ -64,8 +75,8 @@ You could also let the AspectJ plugin run all the processing and disable annotat
6475
[NOTE]
6576
====
6677
If you are using Lombok in your project, you need to make sure that its annotation processor runs before `spring-boot-configuration-processor`.
67-
To do so with Maven, you can list the annotation processors in the right order using the `annotationProcessors` attribute of the Maven compiler plugin.
68-
If you are not using this attribute, and annotation processors are picked up by the dependencies available on the classpath, make sure that the `lombok` dependency is defined before the `spring-boot-configuration-processor` dependency.
78+
To do so with Maven, list the annotation processors in the required order using the `annotationProcessors` attribute of the Maven compiler plugin.
79+
With Gradle, declare the dependencies in the `annotationProcessor` configuration in the required order.
6980
====
7081

7182

0 commit comments

Comments
 (0)