<?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>com.github.aistomin</groupId>
    <artifactId>maven-dependencies-analyser</artifactId>
    <version>5.2</version>
    <packaging>maven-plugin</packaging>
    <!--
        The oldest Maven this plugin supports. For maven-plugin packaging this
        is still the supported mechanism: it becomes requiredMavenVersion in
        the generated plugin descriptor, so a user on an older Maven gets a
        clear error instead of a NoSuchMethodError somewhere in the middle of
        their build.
    -->
    <prerequisites>
        <maven>${mvnMinVersion}</maven>
    </prerequisites>
    <name>Maven Dependencies Analyser</name>
    <description>Maven plugin that analyses and validates Maven dependencies of a project.</description>
    <url>https://github.com/aistomin/maven-dependencies-analyser</url>
    <!--
        The year of first publication and the copyright holder. Apache's
        license text carries these as the placeholders
        "Copyright [yyyy] [name of copyright owner]", so they cannot come from
        LICENSE and have to be stated once somewhere - here. The build fills
        them into the license header of every .java file. The year is the year
        of first publication: it is not a range and is never bumped.
    -->
    <inceptionYear>2019</inceptionYear>
    <organization>
        <name>Andrej Istomin</name>
        <url>https://aistomin.com/</url>
    </organization>
    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <name>Andrej Istomin</name>
            <email>contact@aistomin.com</email>
            <organization>Andrej Istomin</organization>
            <organizationUrl>https://aistomin.com/</organizationUrl>
        </developer>
    </developers>
    <scm>
        <connection>scm:git:github.com:aistomin/maven-dependencies-analyser.git</connection>
        <developerConnection>scm:git:github.com:aistomin/maven-dependencies-analyser.git</developerConnection>
        <url>https://github.com/aistomin/maven-dependencies-analyser</url>
    </scm>
    <distributionManagement>
        <snapshotRepository>
            <id>central</id>
            <url>https://central.sonatype.com/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--
            The Java version, written once for the whole build. "release" is
            deliberately used instead of the "source"/"target" pair: it also
            checks the code against the JDK 21 API, so an API newer than 21
            cannot slip in unnoticed when the build runs on a newer JDK.
        -->
        <maven.compiler.release>21</maven.compiler.release>
        <linkXRef>false</linkXRef>
        <junitVersion>6.1.3</junitVersion>
        <!--
            The oldest supported Maven, defined once and used everywhere it
            matters: the Maven artifacts below, <prerequisites> above, and the
            enforcer rule. Keeping it in one place is what stops the three from
            drifting apart.
        -->
        <mvnMinVersion>3.8.3</mvnMinVersion>
        <!--
            maven-plugin-tools, which releases both maven-plugin-annotations
            and maven-plugin-plugin. Unrelated to the Maven version above.
        -->
        <mvnPluginToolsVersion>3.15.2</mvnPluginToolsVersion>
        <slf4jVersion>2.0.18</slf4jVersion>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.github.aistomin</groupId>
            <artifactId>maven-browser</artifactId>
            <version>5.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4jVersion}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4jVersion}</version>
            <scope>test</scope>
        </dependency>
        <!--
            These three come from the user's Maven installation at runtime, so
            they are compiled against the oldest Maven we support rather than
            the newest one released. That way the compiler proves we only use
            API that exists everywhere down to ${mvnMinVersion}, instead of
            letting a Maven-4-only method compile green here and fail with a
            NoSuchMethodError on a user's machine. Bumping them means dropping
            support for older Maven, which is a deliberate decision, never an
            automatic dependency update - hence the Dependabot ignore rules in
            .github/dependabot.yml.
        -->
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-model</artifactId>
            <version>${mvnMinVersion}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.sisu</groupId>
                    <artifactId>org.eclipse.sisu.plexus</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.sisu</groupId>
                    <artifactId>org.eclipse.sisu.inject</artifactId>
                </exclusion>
            </exclusions>
            <version>${mvnMinVersion}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-artifact</artifactId>
            <version>${mvnMinVersion}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>${mvnPluginToolsVersion}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junitVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junitVersion}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.11.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>central</publishingServerId>
                            <autoPublish>true</autoPublish>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.4.0</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.8</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <plugins>
            <!--
                Enforces the two requirements the README states, at "validate",
                so building this plugin on an unsupported Maven or JDK fails
                immediately with a clear message rather than somewhere later
                with a confusing one. <prerequisites> above covers the users of
                the published plugin; this covers whoever builds it.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.6.3</version>
                <executions>
                    <execution>
                        <id>enforce-versions</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>[${mvnMinVersion},)</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <version>[21,)</version>
                                </requireJavaVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.6</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.15</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>PACKAGE</element>
                                    <limits>
                                        <limit>
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.95</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.16.0</version>
            </plugin>
            <!--
                Derives the license header from LICENSE itself, so the notice
                is never written down a second time.

                LICENSE is the verbatim Apache 2.0 text. Its last 13 lines are
                the "APPENDIX: How to apply the Apache License to your work"
                boilerplate - Apache's own instruction for what every source
                file should carry. Those lines, de-indented and with the
                "Copyright [yyyy] [name of copyright owner]" placeholder
                filled in from <inceptionYear> and <organization> above, are
                exactly the header on every .java file.

                This runs on every build and writes into target/, so the
                extracted header cannot go stale: change LICENSE and the next
                build compares the .java files against the new text.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>extract-license-header</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="${project.basedir}/LICENSE"
                                      tofile="${project.build.directory}/license-header.txt"
                                      overwrite="true">
                                    <filterchain>
                                        <tailfilter lines="13"/>
                                        <tokenfilter>
                                            <trim/>
                                        </tokenfilter>
                                        <replacestring
                                            from="Copyright [yyyy] [name of copyright owner]"
                                            to="Copyright (c) ${project.inceptionYear} ${project.organization.name}"/>
                                    </filterchain>
                                </copy>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--
                Checks the header of every .java file against the notice
                extracted from LICENSE above, and fails the build when a
                header has drifted or is missing. Run
                "mvn validate license:format" to rewrite the headers from
                LICENSE; never edit a header by hand.

                The check runs at process-sources rather than validate so the
                extraction above has already happened, and so that
                license:format is not blocked by the very check it exists to
                satisfy.
            -->
            <plugin>
                <groupId>com.mycila</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <version>5.1.2</version>
                <configuration>
                    <licenseSets>
                        <licenseSet>
                            <header>${project.build.directory}/license-header.txt</header>
                            <includes>
                                <include>src/**/*.java</include>
                            </includes>
                        </licenseSet>
                    </licenseSets>
                    <mapping>
                        <java>SLASHSTAR_STYLE</java>
                    </mapping>
                </configuration>
                <executions>
                    <execution>
                        <id>check-license-headers</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>${mvnPluginToolsVersion}</version>
                <configuration>
                    <goalPrefix>maven-dependencies-analyser</goalPrefix>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.github.aistomin</groupId>
                <artifactId>maven-dependencies-analyser</artifactId>
                <version>5.1</version>
                <configuration>
                    <level>WARNING</level>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.6.0</version>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>14.1.0</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <configLocation>conf/checkstyle.xml</configLocation>
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <linkXRef>false</linkXRef>
                </configuration>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.28.0</version>
                <configuration>
                    <failurePriority>1</failurePriority>
                    <failOnViolation>true</failOnViolation>
                    <printFailingErrors>true</printFailingErrors>
                </configuration>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.basepom.maven</groupId>
                <artifactId>duplicate-finder-maven-plugin</artifactId>
                <version>2.0.1</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.12.0</version>
                <configuration>
                    <!-- Tracks the compiler, so doclint can never end up
                         checking against a different language level than
                         javac compiles with. -->
                    <source>${maven.compiler.release}</source>
                    <!-- Check the content of the Javadoc comments, not only
                         their presence: broken references, tags which do not
                         match the signature, invalid HTML. Warnings fail the
                         build too, otherwise the warning-level findings would
                         pile up unnoticed. -->
                    <doclint>all</doclint>
                    <failOnWarnings>true</failOnWarnings>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                    <!--
                        Checkstyle holds the test sources to the same Javadoc
                        bar as the main ones, so their comments are
                        content-checked too. This is the report goal and not
                        test-jar on purpose: it must not attach a second
                        javadoc artifact to the release.
                    -->
                    <execution>
                        <id>check-test-javadocs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>test-javadoc</goal>
                        </goals>
                        <configuration>
                            <!-- The test classes are package-private, as JUnit
                                 5 wants them. Without this javadoc sees no
                                 documentable class at all and fails. -->
                            <show>private</show>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
