Merged configuration between parent & child?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Merged configuration between parent & child?

Andres Almiray
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 | Threaded
Open this post in threaded view
|

Re: Merged configuration between parent & child?

Anders Hammar
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 <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: Merged configuration between parent & child?

Andres Almiray
Thank you Anders, the `combine.children="append"` attribute applied to the
child's <annotationProcessor> element does the trick.

Wonderful!

On Thu, Oct 15, 2020 at 12:54 PM Anders Hammar <[hidden email]> wrote:

> 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 <[hidden email]>
> 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 | Threaded
Open this post in threaded view
|

Re: Merged configuration between parent & child?

Jörg Schaible
If you put your configuration additionally into a profile in the parent, that is
activated e.g. on the existence of the file "profiles/lombok". Then you can
simply create that in those child projects individually that use the
processor. Personally I share typically the profile's name with the one of the
file in the profiles directory...

On Thursday, 15. October 2020, 13:24:41 CEST Andres Almiray wrote:

> Thank you Anders, the `combine.children="append"` attribute applied to the
> child's <annotationProcessor> element does the trick.
>
> Wonderful!
>
> On Thu, Oct 15, 2020 at 12:54 PM Anders Hammar <[hidden email]> wrote:
> > Maybe this blog post helps:
> >
> > https://blog.sonatype.com/2011/01/maven-how-to-merging-plugin-configuratio
> > n-in-complex-projects/
> >
> > /Anders
> >
> > On Thu, Oct 15, 2020 at 12:25 PM Andres Almiray <[hidden email]>
> >
> > 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





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]