Creating the Single Parent

The single parent is a simple Maven project called project-parent that defines the common build extensions for all projects.

Jenkinsfile
pom.xml

Jenkinsfile

buildApi()

pom.xml

Copy and paste friendly version

    <?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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>

      <groupId>io.practiv.stable.anvil</groupId>
      <artifactId>anvil-parent</artifactId>
      <version>1.999-SNAPSHOT</version>
      <packaging>pom</packaging>

      <name>${project.artifactId}</name>

      <properties>
(1)     <target.dir>target</target.dir>
        <output.basedir>${basedir}</output.basedir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      </properties>

      <build>
(2)     <directory>${output.basedir}/${target.dir}</directory>
        <outputDirectory>${output.basedir}/${target.dir}/classes</outputDirectory>
        <testOutputDirectory>${output.basedir}/${target.dir}/test-classes</testOutputDirectory>

        <extensions>
          <extension>
            <groupId>com.igormaznitsa</groupId>
(3)         <artifactId>mvn-finisher-extension</artifactId>
            <version>1.1.1</version>
          </extension>
        </extensions>

        <plugins>
          <plugin>
            <groupId>io.repaint.maven</groupId>
(4)         <artifactId>tiles-maven-plugin</artifactId>
            <version>2.17</version>
(5)         <extensions>true</extensions>
            <configuration>
(6)           <filtering>true</filtering>
              <tiles>
(7)             <tile>io.practiv.stable.anvil:anvil-tile-build:[1,2)</tile>
              </tiles>
            </configuration>
          </plugin>
        </plugins>
      </build>

      <profiles>
        <profile>
          <id>running-in-eclipse</id>
          <activation>
            <property>
              <name>m2e.version</name>
            </property>
          </activation>
          <properties>
(8)         <target.dir>target-eclipse</target.dir>
          </properties>
        </profile>
      </profiles>

    </project>
  1. Declare a property as the base of all output paths to allow for splitting output for command line and IDE
  2. Use the base of all output
  3. Add finish, finish-success, finish-failure and finish-force to the end of the default lifecycle to allow clean up tasks to run
  4. Run the tiles plugin by default, this means
  5. Enable extensions so that <packaging>tile</packaging> are ready to go
  6. Enable filtering so that project placeholders are replaced at build time e.g. @project.version@
  7. Include the build tile that defines the default build properties and distribution management i.e. how to deploy built artifacts
  8. When running in Eclipse use a different target directory, this means Eclipse and Maven on the command line don’t mess with each other. Its really disconcerting to have the IDE refresh when building on the command line.