<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>com.elastisys</groupId>
  <artifactId>elastisys-pom-root</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <name>elastisys</name>
  <description>
    Elastisys root pom.

    Specializations need to specify a ${docker.registry} property for the
    targeted docker registry (e.g. 'index.docker.io/v1/' or
    'my.private.registry:5000') and may want to specify a template for the
    ${docker.repo} property (such as '${docker.registry}/${docker.image}' for
    a private registry or just '${docker.image}' when using docker hub).
  </description>
  <url>https://elastisys.com/</url>
  <organization>
    <name>Elastisys</name>
    <url>https://elastisys.com</url>
  </organization>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <scm>
    <url>https://github.com/elastisys/elastisys-root-pom</url>
  </scm>

  <developers>
    <developer>
      <id>elastisys</id>
      <name>Elastisys Tech Team</name>
      <email>techteam@elastisys.com</email>
      <url>https://elastisys.com/</url>
      <organization>Elastisys AB</organization>
      <organizationUrl>https://elastisys.com/</organizationUrl>
      <roles>
        <role>developer</role>
      </roles>
      <timezone>+1</timezone>
    </developer>
  </developers>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>

    <docker.plugin.version>1.2.0</docker.plugin.version>
    <docker.image>elastisys/${project.artifactId}</docker.image>
    <docker.repo>${docker.registry}/${docker.image}</docker.repo>
  </properties>

  <build>
    <!-- Strip version from final jar (necessary for the docker plugin since
        filtering is not included atm). -->
    <finalName>${project.artifactId}</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>license-maven-plugin</artifactId>
          <version>1.12</version>
          <configuration>
            <!-- don't include test dependencies in 3rd-party license file -->
            <excludedScopes>test</excludedScopes>
            <outputDirectory>${project.build.directory}</outputDirectory>
            <thirdPartyFilename>third-party-licenses</thirdPartyFilename>
          </configuration>
          <executions>
            <execution>
              <id>generate-license-list</id>
              <goals>
                <goal>add-third-party</goal>
              </goals>
              <phase>generate-resources</phase>
            </execution>
          </executions>
        </plugin>
        <!-- Build a standalone executable jar file that embeds all classpath
             dependencies. A project wishing to make use of this plugin only
             needs to specify the ${shade.mainClass} property and set up the
             build plugin like so

             <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-shade-plugin</artifactId>
             </plugin>

          -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.2.0</version>
          <configuration>
            <transformers>
              <!-- Set jar main class entrypoint -->
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>${shade.mainClass}</mainClass>
              </transformer>
            </transformers>
            <!-- Make shaded jar the main artifact output by the build. -->
            <shadedArtifactAttached>false</shadedArtifactAttached>
            <createDependencyReducedPom>false</createDependencyReducedPom>
            <filters>
              <filter>
                <artifact>*:*</artifact>
                <excludes>
                  <exclude>META-INF/*.SF</exclude>
                  <exclude>META-INF/*.DSA</exclude>
                  <exclude>META-INF/*.RSA</exclude>
                </excludes>
              </filter>
            </filters>
          </configuration>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>shade</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <!-- Build/deploy docker image. A project wishing to make use of this
             plugin only needs to specify the ${docker.image} property and set
             up the build plugin like so

             <plugin>
               <groupId>com.spotify</groupId>
               <artifactId>docker-maven-plugin</artifactId>
             </plugin>

          -->
        <plugin>
          <groupId>com.spotify</groupId>
          <artifactId>docker-maven-plugin</artifactId>
          <version>${docker.plugin.version}</version>
          <configuration>
            <imageName>${docker.image}</imageName>
            <!-- Directory to be copied to target/docker -->
            <dockerDirectory>
              ${project.basedir}/src/main/docker
            </dockerDirectory>
            <resources>
              <!-- include jar file in target/docker directory. -->
              <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
              </resource>
              <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>third-party-licenses</include>
              </resource>
            </resources>
            <imageTags>
              <imageTag>${project.version}</imageTag>
              <imageTag>latest</imageTag>
            </imageTags>
            <forceTags>true</forceTags>
          </configuration>
          <executions>
            <!-- On mvn install: build local Docker image -->
            <execution>
              <id>docker-build</id>
              <phase>install</phase>
              <goals>
                <goal>build</goal>
              </goals>
              <configuration>
                <useConfigFile>true</useConfigFile>
              </configuration>
            </execution>
            <!-- On mvn deploy: (before push) tag image with registry name if published to private registry -->
            <execution>
              <id>docker-tag</id>
              <phase>deploy</phase>
              <goals>
                <goal>tag</goal>
              </goals>
              <configuration>
                <image>${docker.image}:${project.version}</image>
                <newName>
                  ${docker.remoteName}:${project.version}
                </newName>
              </configuration>
            </execution>
            <!-- On mvn deploy: push to registry -->
            <execution>
              <id>docker-push</id>
              <phase>deploy</phase>
              <goals>
                <goal>push</goal>
              </goals>
              <configuration>
                <imageName>
                  ${docker.remoteName}:${project.version}
                </imageName>
                <registryUrl>https://${docker.repo}</registryUrl>
                <!-- Docker registry credentials assumed to be in
                    ~/.docker/config.json -->
                <useConfigFile>true</useConfigFile>
              </configuration>
            </execution>
          </executions>
          <dependencies>
            <!--
              Needed to prevent a bug when building on JDK 9+
              https://github.com/spotify/dockerfile-maven/issues/90
            -->
            <dependency>
              <groupId>javax.activation</groupId>
              <artifactId>activation</artifactId>
              <version>1.1.1</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <!-- Unit tests -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.1</version>
        <configuration>
          <redirectTestOutputToFile>true</redirectTestOutputToFile>
          <argLine>${jacoco.surefireArgLine}</argLine>
        </configuration>
      </plugin>

      <!-- Test coverage -->
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.2</version>
        <executions>
            <execution>
                <id>pre-unit-test</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
                <configuration>
                    <propertyName>jacoco.surefireArgLine</propertyName>
                </configuration>
            </execution>
        </executions>
      </plugin>

      <!-- Compile byte code compatible with the targeted Java version -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>${java.version}</source>
          <target>${java.version}</target>
        </configuration>
      </plugin>

      <!-- Enforce Java version -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireJavaVersion>
                  <version>[${java.version},)</version>
                </requireJavaVersion>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- UTF-8 encoding of resource files -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>3.0.0</version>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <autoVersionSubmodules>true</autoVersionSubmodules>
          <!-- Git tag should only be project version, e.g. "1.0.1" -->
          <tagNameFormat>@{project.version}</tagNameFormat>
          <goals>deploy</goals>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.0</version>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.7.1</version>
          <dependencies>
            <!-- Add support for ssh/scp -->
            <dependency>
              <groupId>org.apache.maven.wagon</groupId>
              <artifactId>wagon-ssh</artifactId>
              <version>1.0</version>
            </dependency>
          </dependencies>
      </plugin>
    </plugins>
  </build>

  <reporting>
    <plugins>
      <!-- Generates various reports for the project site -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
        </configuration>
        <reportSets>
          <reportSet>
            <!-- The reports to generate -->
            <reports>
              <report>index</report>
              <report>project-team</report>
              <report>dependency-management</report>
              <report>dependency-info</report>
              <report>issue-tracking</report>
              <report>modules</report>
              <report>summary</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
      <!-- Javadoc generation plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.0.1</version>
        <configuration>
          <quiet>true</quiet>
          <source>${java.version}</source>
          <links>
            <link>https://docs.oracle.com/javase/8/docs/api/</link>
          </links>
        </configuration>
      </plugin>
      <!-- Java cross-reference plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>3.0.0</version>
      </plugin>
      <!-- Test result report generation -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.22.1</version>
        <configuration>
          <aggregate>true</aggregate>
        </configuration>
      </plugin>
      <!-- Reports test coverage of unit tests -->
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.2</version>
        <!-- Aggregate reports is problematic in multi-module projects
            See: https://github.com/jacoco/jacoco/wiki/MavenMultiModule -->
        <!-- We need to explicitly set which reports we want to include
             to remove empty aggregate reports
            See: http://www.eclemma.org/jacoco/trunk/doc/maven.html -->
        <reportSets>
          <reportSet>
            <reports>
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>

      <!-- Warns when project style conventions are violated -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>3.0.0</version>
        <reportSets>
          <reportSet>
            <reports>
              <report>checkstyle</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>

      <!-- Reports on suspected bug patterns -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>3.0.4</version>
      </plugin>
      <!-- PMD source code analyzer -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.10.0</version>
      </plugin>
    </plugins>
  </reporting>
</project>
