<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.kolich</groupId>
    <artifactId>kolich-build-version</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>kolich-build-version</name>
    <description>The build number, timestamp, version and branch of a running application.</description>
    <url>https://github.com/markkolich/kolich-build-version</url>

    <licenses>
        <license>
            <name>MIT</name>
            <url>https://opensource.org/licenses/MIT</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <id>markkolich</id>
            <name>Mark Kolich</name>
            <email>social@kolich.com</email>
        </developer>
    </developers>

    <properties>
        <!-- The JDK required to run the build: javac, Checkstyle, PMD, and unit tests. -->
        <project.java-build.version>[21,)</project.java-build.version>
        <!-- The Java release the resulting bytecode targets, and so the minimum supported runtime JVM. -->
        <project.java-release.version>11</project.java-release.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.maven.version>3.6.3</project.maven.version>

        <maven-enforcer-plugin.version>3.6.3</maven-enforcer-plugin.version>
        <maven-enforcer-plugin.extra-enforcer-rules.version>1.12.1</maven-enforcer-plugin.extra-enforcer-rules.version>

        <maven-clean-plugin.version>3.5.0</maven-clean-plugin.version>
        <maven-compiler-plugin.version>3.16.0</maven-compiler-plugin.version>
        <maven-surefire-plugin.version>3.6.0</maven-surefire-plugin.version>
        <maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
        <maven-pmd-plugin.version>3.28.0</maven-pmd-plugin.version>
        <maven-pmd-plugin.pmd.version>7.28.0</maven-pmd-plugin.pmd.version>
        <maven-source-plugin.version>3.4.0</maven-source-plugin.version>
        <maven-antrun-plugin.version>3.2.0</maven-antrun-plugin.version>

        <guava.version>33.7.2-jre</guava.version>

        <checkstyle.version>14.3.0</checkstyle.version>

        <!-- Test dependency versions -->

        <junit.jupiter.version>6.1.3</junit.jupiter.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>

        <!-- Test dependencies -->

        <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>

    </dependencies>

    <build>

        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>${maven-clean-plugin.version}</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>dist</directory>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven-enforcer-plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>extra-enforcer-rules</artifactId>
                        <version>${maven-enforcer-plugin.extra-enforcer-rules.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>enforce-build-environment</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>${project.maven.version}</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <version>${project.java-build.version}</version>
                                </requireJavaVersion>
                                <enforceBytecodeVersion>
                                    <maxJdkVersion>${project.java-release.version}</maxJdkVersion>
                                    <ignoredScopes>
                                        <ignoredScope>test</ignoredScope>
                                    </ignoredScopes>
                                </enforceBytecodeVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <release>${project.java-release.version}</release>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>-Xlint:all</arg>
                        <arg>-Xlint:-processing</arg>
                        <arg>-Xlint:-serial</arg>
                        <arg>-Werror</arg>
                    </compilerArgs>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <!-- Keeps the Surefire "ForkedBooter" from popping up in the macOS dock. -->
                        <java.awt.headless>true</java.awt.headless>
                    </systemPropertyVariables>
                    <argLine>-Xshare:off</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${maven-checkstyle-plugin.version}</version>
                <executions>
                    <execution>
                        <id>verify-style</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>${checkstyle.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <configLocation>build/checkstyle/config.xml</configLocation>
                    <violationSeverity>warning</violationSeverity>
                    <failOnViolation>true</failOnViolation>
                    <failsOnError>true</failsOnError>
                    <!-- Validate source files in src/test/java too -->
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${maven-pmd-plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>net.sourceforge.pmd</groupId>
                        <artifactId>pmd-core</artifactId>
                        <version>${maven-pmd-plugin.pmd.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>net.sourceforge.pmd</groupId>
                        <artifactId>pmd-java</artifactId>
                        <version>${maven-pmd-plugin.pmd.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>pmd-check</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <printFailingErrors>true</printFailingErrors>
                    <includeTests>true</includeTests>
                    <failOnViolation>true</failOnViolation>
                    <linkXRef>false</linkXRef>
                    <targetJdk>${project.java-release.version}</targetJdk>
                    <rulesets>
                        <ruleset>build/pmd/ruleset.xml</ruleset>
                    </rulesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven-source-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--
                Lays out dist/: the JAR, sources JAR and POM, each with the .md5/.sha1
                checksum sidecar files a real Maven repository expects. Publish by copying
                dist/kolich-build-version/${project.version} into the markkolich.github.io repo under
                repo/com/kolich/kolich-build-version/.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>${maven-antrun-plugin.version}</version>
                <executions>
                    <execution>
                        <id>dist-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <property name="dist.dir" value="dist/${project.artifactId}/${project.version}" />
                                <copy todir="${dist.dir}">
                                    <fileset dir="${project.build.directory}">
                                        <include name="${project.build.finalName}.jar" />
                                        <include name="${project.build.finalName}-sources.jar" />
                                    </fileset>
                                </copy>
                                <copy file="pom.xml" tofile="${dist.dir}/${project.build.finalName}.pom" />
                                <checksum algorithm="MD5" fileext=".md5">
                                    <fileset dir="${dist.dir}">
                                        <include name="*.jar" />
                                        <include name="*.pom" />
                                    </fileset>
                                </checksum>
                                <checksum algorithm="SHA-1" fileext=".sha1">
                                    <fileset dir="${dist.dir}">
                                        <include name="*.jar" />
                                        <include name="*.pom" />
                                    </fileset>
                                </checksum>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>

</project>
