Maybe this blog post helps:
https://blog.sonatype.com/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/

/Anders

On Thu, Oct 15, 2020 at 12:25 PM Andres Almiray <[email protected]> wrote:

> Hello everyone,
>
> I wonder if it's possible to define a plugin's configuration on both parent
> & child in such a way that the resulting configuration is merged, first
> the  parent's then the child's. My use case is defining a set of annotation
> processors in the maven-compiler-plugin at the parent, also adding another
> set in the child's maven-compiler-plugin.
>
> The following example is NOT explicitly related to Lombok nor AutoValue,
> they are used just as reference. Suggestions to skip Lombok and/or
> AutoValue are not needed, thanks.
>
> Given a parent pom such as
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance";
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd";>
>     <modelVersion>4.0.0</modelVersion>
>     <groupId>com.acme</groupId>
>     <artifactId>parent</artifactId>
>     <version>0.0.0</version>
>     <packaging>pom</packaging>
>
>     <properties>
>         <auto-value.version>1.7.4</auto-value.version>
>         <lombok.version>1.18.14</lombok.version>
>     </properties>
>
>     <build>
>         <pluginManagement>
>             <plugins>
>                 <plugin>
>                   <groupId>org.apache.maven.plugins</groupId>
>                   <artifactId>maven-compiler-plugin</artifactId>
>                   <version>3.8.1</version>
>                   <configuration>
>                       <annotationProcessorPaths>
>                           <path>
>                               <groupId>org.projectlombok</groupId>
>                               <artifactId>lombok</artifactId>
>                               <version>1.18.14</version>
>                           </path>
>                       </annotationProcessorPaths>
>                   </configuration>
>                 </plugin>
>             </plugins>
>         </pluginManagement>
>     </build>
> </project>
>
> And a child pom as
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance";
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd";>
>     <modelVersion>4.0.0</modelVersion>
>
>     <parent>
>         <groupId>com.acme</groupId>
>         <artifactId>parent</artifactId>
>         <version>0.0.0</version>
>     </parent>
>
>     <artifactId>child</artifactId>
>
>     <build>
>         <plugins>
>             <plugin>
>               <groupId>org.apache.maven.plugins</groupId>
>               <artifactId>maven-compiler-plugin</artifactId>
>               <version>3.8.1</version>
>               <inherited>true</inherited>
>               <configuration>
>                   <annotationProcessorPaths>
>                       <path>
>                           <groupId>com.google.auto.value</groupId>
>                           <artifactId>auto-value</artifactId>
>                           <version>${auto-value.version}</version>
>                       </path>
>                   </annotationProcessorPaths>
>               </configuration>
>             </plugin>
>         </plugins>
>     </build>
> </project>
>
> The desired result when evaluating the child's pom is to have both Lombok
> and AutoValue (in that order) in the compiler's configuration. As it
> currently stands with Maven 3.6.3 only the child configuration is
> available, as shown by running `mvn help:effective-pom`
>
>       <plugin>
>         <artifactId>maven-compiler-plugin</artifactId>
>         <version>3.8.1</version>
>         <executions>
>           <execution>
>             <id>default-compile</id>
>             <phase>compile</phase>
>             <goals>
>               <goal>compile</goal>
>             </goals>
>             <configuration>
>               <annotationProcessorPaths>
>                 <path>
>                   <groupId>com.google.auto.value</groupId>
>                   <artifactId>auto-value</artifactId>
>                   <version>1.7.4</version>
>                 </path>
>               </annotationProcessorPaths>
>             </configuration>
>           </execution>
>           <execution>
>             <id>default-testCompile</id>
>             <phase>test-compile</phase>
>             <goals>
>               <goal>testCompile</goal>
>             </goals>
>             <configuration>
>               <annotationProcessorPaths>
>                 <path>
>                   <groupId>com.google.auto.value</groupId>
>                   <artifactId>auto-value</artifactId>
>                   <version>1.7.4</version>
>                 </path>
>               </annotationProcessorPaths>
>             </configuration>
>           </execution>
>         </executions>
>         <inherited>true</inherited>
>         <configuration>
>           <annotationProcessorPaths>
>             <path>
>               <groupId>com.google.auto.value</groupId>
>               <artifactId>auto-value</artifactId>
>               <version>1.7.4</version>
>             </path>
>           </annotationProcessorPaths>
>         </configuration>
>       </plugin>
>
> Cheers,
> Andres
>

Reply via email to