You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by George Kopf <ge...@gmail.com> on 2017/06/05 12:42:21 UTC

Re: Inject xml into the POM for build specific elements.

Thank you for your help.  I figured it out using the tiles-maven-plugin.

After fighting through the documentation I put together a simple tile and
pulled it into my pom.

To clarify what the docs are saying:

1.  The tile will be called tile.xml, will be installed in your maven
repository along with a pom.xml that has uses the tiles-maven-plugin.
2.  The project pom also uses the tiles-maven-plugin but it has the
configuration element to reference your tile.


Here is a concrete example of a tile for the jacoco plugin and then inject
the tile into your project pom.

tile.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<build>
    <plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.9</version>
        <executions>
            <execution>
                <id>default-prepare-agent</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>default-report</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>report</goal>
                </goals>
            </execution>
            <execution>
                <id>default-check</id>
                <goals>
                    <goal>check</goal>
                </goals>
                <configuration>
                    <rules>
                        <!--  implementation is needed only for Maven 2 -->
                        <rule
implementation="org.jacoco.maven.RuleConfiguration">
                            <element>BUNDLE</element>
                            <limits>
                                <!--  implementation is needed only for
Maven 2  -->
                                <limit
implementation="org.jacoco.report.check.Limit">
                                    <counter>COMPLEXITY</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.0</minimum>
                                </limit>
                            </limits>
                        </rule>
                    </rules>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
</build>
</project>




pom.xml that accompanies the tile.xml in your maven repository

<?xml version="1.0" encoding="UTF-8"?>
<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>edu.school</groupId>
    <artifactId>cdp_build_tile</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>tile</packaging>

    <distributionManagement>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Repository</name>
            <layout>default</layout>
            <url>
http://server.school.edu:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <layout>default</layout>
            <url>http://server.school.edu:8081/nexus</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>io.repaint.maven</groupId>
                <artifactId>tiles-maven-plugin</artifactId>
                <version>2.10</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>


build section of your project's pom
    <build>
        <plugins>
            <plugin>
                <groupId>io.repaint.maven</groupId>
                <artifactId>tiles-maven-plugin</artifactId>
                <version>2.10</version>
                <extensions>true</extensions>
                <configuration>
                    <filtering>false</filtering>
                    <tiles>
                        <tile>edu.school:cdp_build_tile:1.0-SNAPSHOT</tile>
                    </tiles>
                </configuration>
            </plugin>
        </plugins>
    </build>





On Tue, May 30, 2017 at 1:25 PM, Karl Heinz Marbaise <kh...@gmx.de>
wrote:

> Hi,
>
> On 30/05/17 16:44, George Kopf wrote:
>
>> I apologize if this topic has already been discussed.  I searched all over
>> the web and the archives and didn't find anything, but I can't believe
>> that
>> I'm the only person with this request.
>>
>
> No need to apologize for asking...
>
>
>> I'm running the CI/CD pipeline for several java projects.
>>
>> We're using Git, Maven, Jenkins, Sonar, and Nexus.
>>
>> I would like to to have the developers create and own their own POM.XML
>> that will be used for Snapshots and Release Candidates.
>>
>
> and in consequence also for releases ?
>
>
>> I want to add my build specific POM elements to the effective POM for the
>> CI process but I don't want their POM to have to include all the extra
>> elements for Jacoco and Sonar (and whatever else we add in the future >
>> I can do this with profiles but then their POM will have everything in it.
>> I can do this with a parent POM but they already have a parent POM
>> (springboot) so that they can run locally.
>>
>
> If you have springboot as parent it might be a good choice to use spring
> as bom instead of as a parent...than you can control things different and
> better...
>
> Does it not work ?
>
> So where is the difference for a CI pom and usual pom file ?
>
> >
> I would have to insert my
>
>> parent pom in between and that seems fragile since mine is only for CI
>> builds.
>>
>
> What exactly is fragile here?
>
>
>
>> I can't do this with the settings.xml, on the build server, because it
>> doesn't have all the required elements.
>>
>
> Sure the settings.xml has a different purpose...
>
>
>> I hope that there is something obvious that I've missed (like a Jenkins
>> plugin) but I'm about to give up and just require the developers to live
>> with an excessively complicated POM file.
>>
>
>
> Maybe it's worth to take al look at the tiles-maven-plugin[1] which might
> help here...
>
>
> Maybe you can give an example what becomes so long or complicated ?
>
>
> Kind regards
> Karl Heinz Marbaise
>
> [1]: https://github.com/repaint-io/maven-tiles
>



-- 
George Kopf

Re: Inject xml into the POM for build specific elements.

Posted by George Kopf <ge...@gmail.com>.
Thanks!  We're using Maven 3.  I just haven't refactored the pom yet.

On Mon, Jun 5, 2017 at 8:47 AM, Karl Heinz Marbaise <kh...@gmx.de>
wrote:

> Hi George,
>
> based on the comments in your example...
>
> Are you really using Maven 2 ? Please remove it...cause it's long end of
> life...
>
>
> Furthermore the repositories should be defined in users settings.xml and
> not inside the pom file...The distributionManagement should be done in a
> corporate pom only once...
>
> Kind regards
> Karl Heinz Marbaise
>
>
> On 05/06/17 14:42, George Kopf wrote:
>
>> Thank you for your help.  I figured it out using the tiles-maven-plugin.
>>
>> After fighting through the documentation I put together a simple tile and
>> pulled it into my pom.
>>
>> To clarify what the docs are saying:
>>
>> 1.  The tile will be called tile.xml, will be installed in your maven
>> repository along with a pom.xml that has uses the tiles-maven-plugin.
>> 2.  The project pom also uses the tiles-maven-plugin but it has the
>> configuration element to reference your tile.
>>
>>
>> Here is a concrete example of a tile for the jacoco plugin and then
>> inject the tile into your project pom.
>>
>> tile.xml
>> <?xml version="1.0" encoding="UTF-8"?>
>> <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">
>> <build>
>>      <plugins>
>>      <plugin>
>>          <groupId>org.jacoco</groupId>
>>          <artifactId>jacoco-maven-plugin</artifactId>
>>          <version>0.7.9</version>
>>          <executions>
>>              <execution>
>>                  <id>default-prepare-agent</id>
>>                  <goals>
>>                      <goal>prepare-agent</goal>
>>                  </goals>
>>              </execution>
>>              <execution>
>>                  <id>default-report</id>
>>                  <phase>prepare-package</phase>
>>                  <goals>
>>                      <goal>report</goal>
>>                  </goals>
>>              </execution>
>>              <execution>
>>                  <id>default-check</id>
>>                  <goals>
>>                      <goal>check</goal>
>>                  </goals>
>>                  <configuration>
>>                      <rules>
>>                          <!--  implementation is needed only for Maven 2
>> -->
>>                          <rule implementation="org.jacoco.mav
>> en.RuleConfiguration">
>>                              <element>BUNDLE</element>
>>                              <limits>
>>                                  <!--  implementation is needed only for
>> Maven 2  -->
>>                                  <limit implementation="org.jacoco.rep
>> ort.check.Limit">
>>                                      <counter>COMPLEXITY</counter>
>>                                      <value>COVEREDRATIO</value>
>>                                      <minimum>0.0</minimum>
>>                                  </limit>
>>                              </limits>
>>                          </rule>
>>                      </rules>
>>                  </configuration>
>>              </execution>
>>          </executions>
>>      </plugin>
>> </plugins>
>> </build>
>> </project>
>>
>>
>>
>>
>> pom.xml that accompanies the tile.xml in your maven repository
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <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>edu.school</groupId>
>>      <artifactId>cdp_build_tile</artifactId>
>>      <version>1.0-SNAPSHOT</version>
>>      <packaging>tile</packaging>
>>
>>      <distributionManagement>
>>          <snapshotRepository>
>>              <id>snapshots</id>
>>              <name>Nexus Repository</name>
>>              <layout>default</layout>
>>              <url>http://server.school.edu:8081/nexus/content/reposit
>> ories/snapshots</url>
>>          </snapshotRepository>
>>      </distributionManagement>
>>
>>      <repositories>
>>          <repository>
>>              <id>nexus</id>
>>              <name>Nexus Repository</name>
>>              <layout>default</layout>
>>              <url>http://server.school.edu:8081/nexus</url>
>>              <snapshots>
>>                  <enabled>true</enabled>
>>              </snapshots>
>>          </repository>
>>      </repositories>
>>      <build>
>>          <plugins>
>>              <plugin>
>>                  <groupId>io.repaint.maven</groupId>
>>                  <artifactId>tiles-maven-plugin</artifactId>
>>                  <version>2.10</version>
>>                  <extensions>true</extensions>
>>              </plugin>
>>          </plugins>
>>      </build>
>> </project>
>>
>>
>> build section of your project's pom
>>      <build>
>>          <plugins>
>>              <plugin>
>>                  <groupId>io.repaint.maven</groupId>
>>                  <artifactId>tiles-maven-plugin</artifactId>
>>                  <version>2.10</version>
>>                  <extensions>true</extensions>
>>                  <configuration>
>>                      <filtering>false</filtering>
>>                      <tiles>
>>                          <tile>edu.school:cdp_build_ti
>> le:1.0-SNAPSHOT</tile>
>>                      </tiles>
>>                  </configuration>
>>              </plugin>
>>          </plugins>
>>      </build>
>>
>>
>>
>>
>>
>> On Tue, May 30, 2017 at 1:25 PM, Karl Heinz Marbaise <khmarbaise@gmx.de
>> <ma...@gmx.de>> wrote:
>>
>>     Hi,
>>
>>     On 30/05/17 16:44, George Kopf wrote:
>>
>>         I apologize if this topic has already been discussed.  I
>>         searched all over
>>         the web and the archives and didn't find anything, but I can't
>>         believe that
>>         I'm the only person with this request.
>>
>>
>>     No need to apologize for asking...
>>
>>
>>         I'm running the CI/CD pipeline for several java projects.
>>
>>         We're using Git, Maven, Jenkins, Sonar, and Nexus.
>>
>>         I would like to to have the developers create and own their own
>>         POM.XML
>>         that will be used for Snapshots and Release Candidates.
>>
>>
>>     and in consequence also for releases ?
>>
>>
>>         I want to add my build specific POM elements to the effective
>>         POM for the
>>         CI process but I don't want their POM to have to include all the
>>         extra
>>         elements for Jacoco and Sonar (and whatever else we add in the
>>         future >
>>         I can do this with profiles but then their POM will have
>>         everything in it.
>>         I can do this with a parent POM but they already have a parent POM
>>         (springboot) so that they can run locally.
>>
>>
>>     If you have springboot as parent it might be a good choice to use
>>     spring as bom instead of as a parent...than you can control things
>>     different and better...
>>
>>     Does it not work ?
>>
>>     So where is the difference for a CI pom and usual pom file ?
>>
>>     >
>>     I would have to insert my
>>
>>         parent pom in between and that seems fragile since mine is only
>>         for CI
>>         builds.
>>
>>
>>     What exactly is fragile here?
>>
>>
>>
>>         I can't do this with the settings.xml, on the build server,
>>         because it
>>         doesn't have all the required elements.
>>
>>
>>     Sure the settings.xml has a different purpose...
>>
>>
>>         I hope that there is something obvious that I've missed (like a
>>         Jenkins
>>         plugin) but I'm about to give up and just require the developers
>>         to live
>>         with an excessively complicated POM file.
>>
>>
>>
>>     Maybe it's worth to take al look at the tiles-maven-plugin[1] which
>>     might help here...
>>
>>
>>     Maybe you can give an example what becomes so long or complicated ?
>>
>>
>>     Kind regards
>>
>


-- 
George Kopf

Re: Inject xml into the POM for build specific elements.

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi George,

based on the comments in your example...

Are you really using Maven 2 ? Please remove it...cause it's long end of 
life...


Furthermore the repositories should be defined in users settings.xml and 
not inside the pom file...The distributionManagement should be done in a 
corporate pom only once...

Kind regards
Karl Heinz Marbaise


On 05/06/17 14:42, George Kopf wrote:
> Thank you for your help.  I figured it out using the tiles-maven-plugin.
> 
> After fighting through the documentation I put together a simple tile 
> and pulled it into my pom.
> 
> To clarify what the docs are saying:
> 
> 1.  The tile will be called tile.xml, will be installed in your maven 
> repository along with a pom.xml that has uses the tiles-maven-plugin.
> 2.  The project pom also uses the tiles-maven-plugin but it has the 
> configuration element to reference your tile.
> 
> 
> Here is a concrete example of a tile for the jacoco plugin and then 
> inject the tile into your project pom.
> 
> tile.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <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">
> <build>
>      <plugins>
>      <plugin>
>          <groupId>org.jacoco</groupId>
>          <artifactId>jacoco-maven-plugin</artifactId>
>          <version>0.7.9</version>
>          <executions>
>              <execution>
>                  <id>default-prepare-agent</id>
>                  <goals>
>                      <goal>prepare-agent</goal>
>                  </goals>
>              </execution>
>              <execution>
>                  <id>default-report</id>
>                  <phase>prepare-package</phase>
>                  <goals>
>                      <goal>report</goal>
>                  </goals>
>              </execution>
>              <execution>
>                  <id>default-check</id>
>                  <goals>
>                      <goal>check</goal>
>                  </goals>
>                  <configuration>
>                      <rules>
>                          <!--  implementation is needed only for Maven 2 -->
>                          <rule 
> implementation="org.jacoco.maven.RuleConfiguration">
>                              <element>BUNDLE</element>
>                              <limits>
>                                  <!--  implementation is needed only for 
> Maven 2  -->
>                                  <limit 
> implementation="org.jacoco.report.check.Limit">
>                                      <counter>COMPLEXITY</counter>
>                                      <value>COVEREDRATIO</value>
>                                      <minimum>0.0</minimum>
>                                  </limit>
>                              </limits>
>                          </rule>
>                      </rules>
>                  </configuration>
>              </execution>
>          </executions>
>      </plugin>
> </plugins>
> </build>
> </project>
> 
> 
> 
> 
> pom.xml that accompanies the tile.xml in your maven repository
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <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>edu.school</groupId>
>      <artifactId>cdp_build_tile</artifactId>
>      <version>1.0-SNAPSHOT</version>
>      <packaging>tile</packaging>
> 
>      <distributionManagement>
>          <snapshotRepository>
>              <id>snapshots</id>
>              <name>Nexus Repository</name>
>              <layout>default</layout>
>              
> <url>http://server.school.edu:8081/nexus/content/repositories/snapshots</url>
>          </snapshotRepository>
>      </distributionManagement>
> 
>      <repositories>
>          <repository>
>              <id>nexus</id>
>              <name>Nexus Repository</name>
>              <layout>default</layout>
>              <url>http://server.school.edu:8081/nexus</url>
>              <snapshots>
>                  <enabled>true</enabled>
>              </snapshots>
>          </repository>
>      </repositories>
>      <build>
>          <plugins>
>              <plugin>
>                  <groupId>io.repaint.maven</groupId>
>                  <artifactId>tiles-maven-plugin</artifactId>
>                  <version>2.10</version>
>                  <extensions>true</extensions>
>              </plugin>
>          </plugins>
>      </build>
> </project>
> 
> 
> build section of your project's pom
>      <build>
>          <plugins>
>              <plugin>
>                  <groupId>io.repaint.maven</groupId>
>                  <artifactId>tiles-maven-plugin</artifactId>
>                  <version>2.10</version>
>                  <extensions>true</extensions>
>                  <configuration>
>                      <filtering>false</filtering>
>                      <tiles>
>                          <tile>edu.school:cdp_build_tile:1.0-SNAPSHOT</tile>
>                      </tiles>
>                  </configuration>
>              </plugin>
>          </plugins>
>      </build>
> 
> 
> 
> 
> 
> On Tue, May 30, 2017 at 1:25 PM, Karl Heinz Marbaise <khmarbaise@gmx.de 
> <ma...@gmx.de>> wrote:
> 
>     Hi,
> 
>     On 30/05/17 16:44, George Kopf wrote:
> 
>         I apologize if this topic has already been discussed.  I
>         searched all over
>         the web and the archives and didn't find anything, but I can't
>         believe that
>         I'm the only person with this request.
> 
> 
>     No need to apologize for asking...
> 
> 
>         I'm running the CI/CD pipeline for several java projects.
> 
>         We're using Git, Maven, Jenkins, Sonar, and Nexus.
> 
>         I would like to to have the developers create and own their own
>         POM.XML
>         that will be used for Snapshots and Release Candidates.
> 
> 
>     and in consequence also for releases ?
> 
> 
>         I want to add my build specific POM elements to the effective
>         POM for the
>         CI process but I don't want their POM to have to include all the
>         extra
>         elements for Jacoco and Sonar (and whatever else we add in the
>         future >
>         I can do this with profiles but then their POM will have
>         everything in it.
>         I can do this with a parent POM but they already have a parent POM
>         (springboot) so that they can run locally.
> 
> 
>     If you have springboot as parent it might be a good choice to use
>     spring as bom instead of as a parent...than you can control things
>     different and better...
> 
>     Does it not work ?
> 
>     So where is the difference for a CI pom and usual pom file ?
> 
>     >
>     I would have to insert my
> 
>         parent pom in between and that seems fragile since mine is only
>         for CI
>         builds.
> 
> 
>     What exactly is fragile here?
> 
> 
> 
>         I can't do this with the settings.xml, on the build server,
>         because it
>         doesn't have all the required elements.
> 
> 
>     Sure the settings.xml has a different purpose...
> 
> 
>         I hope that there is something obvious that I've missed (like a
>         Jenkins
>         plugin) but I'm about to give up and just require the developers
>         to live
>         with an excessively complicated POM file.
> 
> 
> 
>     Maybe it's worth to take al look at the tiles-maven-plugin[1] which
>     might help here...
> 
> 
>     Maybe you can give an example what becomes so long or complicated ?
> 
> 
>     Kind regards

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org