<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright © 2018 Coda Hale (coda.hale@gmail.com)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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.codahale</groupId>
  <artifactId>common-pom</artifactId>
  <version>0.0.11</version>
  <packaging>pom</packaging>
  <name>common-pom</name>
  <url>https://github.com/codahale/common-pom</url>
  <description>
    A common POM for Java software written by Coda Hale.
  </description>

  <!--
      Everything's released under the Apache License, since it was written by real lawyers and is
      generally chill for the folks at giant, billion-dollar companies who like to turn my hobbies
      into money.
  -->
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <inceptionYear>2018</inceptionYear>
  <scm>
    <connection>scm:git:https://github.com/codahale/common-pom.git</connection>
    <developerConnection>scm:git:https://github.com/codahale/common-pom.git
    </developerConnection>
    <url>https://github.com/codahale/common-pom</url>
    <tag>v0.0.11</tag>
  </scm>

  <developers>
    <developer>
      <name>Coda Hale</name>
      <email>coda.hale@gmail.com</email>
      <timezone>America/Los_Angeles</timezone>
      <url>https://codahale.com/</url>
    </developer>
  </developers>

  <properties>
    <!-- I'm writing Java 8 until the next LTS release comes out. -->
    <maven.compiler.release>8</maven.compiler.release>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <!-- Ensure all files are treated with respect. -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Versions of various dependencies. -->
    <google-java-format.version>1.6</google-java-format.version>
    <jmh.version>1.21</jmh.version>
    <junit.jupiter.version>5.3.1</junit.jupiter.version>
    <spotbugs.version>3.1.6</spotbugs.version>

    <!-- When running `-Pbench exec:exec`, default to show the help. -->
    <bench.args>-h</bench.args>
  </properties>

  <!-- Dependencies which I almost always use. -->
  <dependencies>
    <!-- Testing infrastructure and assertion libraries. -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit.jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit.jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <version>${junit.jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>3.11.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.quicktheories</groupId>
      <artifactId>quicktheories</artifactId>
      <version>0.25</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>2.22.0</version>
      <scope>test</scope>
    </dependency>
    <!-- Benchmarking infrastructure. -->
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-core</artifactId>
      <version>${jmh.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-generator-annprocess</artifactId>
      <version>${jmh.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <!-- Dependencies which I often use but not always. -->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>26.0-jre</version>
        <exclusions>
          <exclusion>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
  </distributionManagement>

  <profiles>
    <!-- Automatically sign all artifacts with GPG when releasing. -->
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- Provide support for running JMH benchmarks via `-Pbench exec:exec`. -->
    <!-- To specify arguments, override the `bench.args` property. -->
    <!-- e.g. `-Pbench exec:exec -Dbench.args=.*` -->
    <profile>
      <id>bench</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <configuration>
              <classpathScope>test</classpathScope>
              <executable>java</executable>
              <arguments>
                <argument>-classpath</argument>
                <classpath />
                <argument>org.openjdk.jmh.Main</argument>
                <argument>${bench.args}</argument>
              </arguments>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <build>
    <!-- Use the latest version of various Maven plugins. -->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </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-resources-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>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <!-- Enable JUnit 5 tests. -->
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
      </plugin>
      <!-- Configure releases with the Sonatype OSS repo. -->
      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6.8</version>
        <extensions>true</extensions>
        <configuration>
          <serverId>ossrh</serverId>
          <nexusUrl>https://oss.sonatype.org/</nexusUrl>
          <autoReleaseAfterClose>true</autoReleaseAfterClose>
        </configuration>
      </plugin>
      <!-- Enable source artifacts. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.0.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- Enable javadoc artifacts. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.0.1</version>
        <configuration>
          <additionalOptions>
            <!-- Generate HTML5 docs. -->
            <option>-html5</option>
          </additionalOptions>
        </configuration>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- Use a `v0.0.0` format for tagging releases in Git. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <autoVersionSubmodules>true</autoVersionSubmodules>
          <useReleaseProfile>false</useReleaseProfile>
          <releaseProfiles>release</releaseProfiles>
          <goals>deploy</goals>
          <tagNameFormat>v@{project.version}</tagNameFormat>
          <preparationGoals>clean verify</preparationGoals>
        </configuration>
      </plugin>
      <!-- Enable lint warnings on compile. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <showWarnings>true</showWarnings>
          <compilerArgs>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-processing</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <!--
          Check to make sure we're both declaring all of our used dependencies and using all our
          declared dependencies.
       -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.1</version>
        <dependencies>
          <!-- use new version of OW2 ASM which supports Java 11 -->
          <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>6.2</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>analyze</id>
            <goals>
              <goal>analyze-only</goal>
            </goals>
            <configuration>
              <!--
                  Don't fail the build on dependency issues, since some libraries make this
                  impossible (AWS SDK, GCP SDK, etc.).
               -->
              <failOnWarning>false</failOnWarning>
              <!-- These are test or optional dependencies from this POM. -->
              <ignoredDependencies>
                <ignoredDependency>com.google.auto.value:auto-value</ignoredDependency>
                <ignoredDependency>com.google.code.findbugs:jsr305</ignoredDependency>
                <ignoredDependency>org.junit.jupiter:junit-jupiter-engine</ignoredDependency>
                <ignoredDependency>org.junit.jupiter:junit-jupiter-params</ignoredDependency>
                <ignoredDependency>org.mockito:mockito-core</ignoredDependency>
                <ignoredDependency>org.openjdk.jmh:jmh-core</ignoredDependency>
                <ignoredDependency>org.openjdk.jmh:jmh-generator-annprocess</ignoredDependency>
                <ignoredDependency>org.quicktheories:quicktheories</ignoredDependency>
              </ignoredDependencies>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Enforce good behavior for all projects. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.0.0-M2</version>
        <executions>
          <execution>
            <id>enforce</id>
            <configuration>
              <fail>false</fail>
              <rules>
                <!--
                    Requires that the version for each dependency resolved during a build, is equal
                    to or higher than all transitive dependency declarations.
                 -->
                <requireUpperBoundDeps />
                <!-- Require a license file in every project. -->
                <requireFilesExist>
                  <files>
                    <file>LICENSE</file>
                  </files>
                </requireFilesExist>
                <!-- Require that the license file be the official Apache License. -->
                <requireFileChecksum>
                  <file>LICENSE</file>
                  <checksum>cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30
                  </checksum>
                  <type>sha256</type>
                </requireFileChecksum>
              </rules>
            </configuration>
            <goals>
              <goal>enforce</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- Automatically manage file headers for the Apache License. -->
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
          <properties>
            <owner>Coda Hale</owner>
            <email>coda.hale@gmail.com</email>
          </properties>
          <mapping>
            <java>SLASHSTAR_STYLE</java>
          </mapping>
          <useDefaultExcludes />
          <excludes>
            <!-- Ignore license files. -->
            <exclude>LICENSE</exclude>
            <!-- Ignore text files. -->
            <exclude>**/*.txt</exclude>
            <!-- Ignore all resource files. -->
            <exclude>src/main/resources/**</exclude>
            <exclude>src/test/resources/**</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>format</goal>
            </goals>
            <phase>process-sources</phase>
          </execution>
        </executions>
      </plugin>
      <!--
          Automatically format all Java code using the Google Java Style:
          https://google.github.io/styleguide/javaguide.html
       -->
      <plugin>
        <groupId>com.coveo</groupId>
        <artifactId>fmt-maven-plugin</artifactId>
        <version>2.5.1</version>
        <executions>
          <execution>
            <goals>
              <goal>format</goal>
            </goals>
            <phase>process-sources</phase>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>com.google.googlejavaformat</groupId>
            <artifactId>google-java-format</artifactId>
            <version>${google-java-format.version}</version>
          </dependency>
        </dependencies>
      </plugin>
      <!-- Enable static analysis with Spotbugs. -->
      <plugin>
        <groupId>com.github.spotbugs</groupId>
        <artifactId>spotbugs-maven-plugin</artifactId>
        <version>${spotbugs.version}</version>
        <configuration>
          <effort>max</effort>
          <excludeFilterFile>spotbugs.xml</excludeFilterFile>
          <nested>false</nested>
          <threshold>low</threshold>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs</artifactId>
            <version>3.1.7</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
            <phase>verify</phase>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
