<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>io.vanillabp</groupId>
  <artifactId>release-parent</artifactId>
  <version>1.2.1</version>
  <packaging>pom</packaging>

  <name>VanillaBP - Release Parent Pom</name>
  <description>This pom defines the required plugins and profiles to perfom a release build.</description>
  <url>https://www.vanillabp.io</url>

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

  <developers>
    <developer>
      <id>VanillaBP</id>
      <organization>Phactum Softwareentwicklung GmbH</organization>
      <organizationUrl>https://www.phactum.at</organizationUrl>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:https://github.com/vanillabp/maven-release-parent.git</connection>
    <developerConnection>scm:git:https://github.com/vanillabp/maven-release-parent.git</developerConnection>
    <url>http://github.com/vanillabp/spi-for-java/tree/main</url>
  </scm>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <skip.central.release>false</skip.central.release>
  </properties>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <!-- Pin version down to 2.5 to be able to run on JDK 17 -->
          <version>2.5</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>3.2.1</version>
          <executions>
            <execution>
              <id>attach-sources</id>
              <phase>package</phase>
              <goals>
                <goal>jar</goal>
              </goals>
              <configuration>
                <attach>true</attach>
                <forceCreation>true</forceCreation>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>3.12.0</version>
          <configuration>
            <!-- javadoc runs in every build. A goal nobody runs stops working without
                 anybody noticing, and the release is a bad moment to find that out, because
                 that is when the javadoc artifact is built.
                 It breaks on errors, which is a reference javadoc cannot resolve or broken
                 HTML. It lets warnings pass, which is mostly a missing comment. Those
                 warnings are older than this binding and cleaning them up is work of its
                 own. -->
            <doclint>all</doclint>
            <failOnError>true</failOnError>
            <failOnWarnings>false</failOnWarnings>
            <!-- no link into the JDK API: that link is fetched over the network, and the
                 check should give the same answer on a machine without one. No link into
                 the javadoc of the other modules either: it is not built at this point,
                 and every module would report the miss -->
            <detectJavaApiLink>false</detectJavaApiLink>
            <detectOfflineLinks>false</detectOfflineLinks>
            <!-- javadoc reports 100 warnings per module and then stops, in one line which
                 reads like the end of the list. Whoever counts warnings to see how much
                 work a module still holds counts too few, and a repository which has more
                 than a hundred in one module learns that only after fixing the first
                 hundred. The number below is high enough that no module reaches it.
                 The run is incremental as well: a module whose sources did not move since
                 the last run is skipped and reports nothing at all. Delete
                 'target/reports/apidocs' before counting, otherwise a clean count means
                 nothing more than that nobody recompiled. -->
            <additionalOptions>
              <additionalOption>-Xmaxwarns 100000</additionalOption>
            </additionalOptions>
          </configuration>
          <executions>
            <execution>
              <id>check-javadoc</id>
              <goals>
                <!-- no fork: the sources are there by this phase -->
                <goal>javadoc-no-fork</goal>
              </goals>
              <!-- after the tests, so a javadoc error does not hide a test result, and
                   still inside a plain 'mvn install' -->
              <phase>package</phase>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>3.0.1</version>
          <executions>
            <execution>
              <id>sign-artifacts</id>
              <phase>verify</phase>
              <goals>
                <goal>sign</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <gpgArguments>
              <arg>--pinentry-mode</arg>
              <arg>loopback</arg>
            </gpgArguments>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <!-- named here and not only managed above, so a repository which inherits this pom
           gets the javadoc check without writing anything of its own. A module which
           documents package-private classes only still has to set 'show' to 'package',
           because that is a property of the module and not of the check. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <!-- the javadoc artifact a release ships. It is bound here and not in the
                   managed section, so an ordinary build runs the check but does not pack a
                   jar nobody asked for. The configuration above applies to this execution
                   too, so a release can no longer attach a javadoc which does not build. -->
              <execution>
                <id>attach-javadocs</id>
                <phase>package</phase>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>central-portal</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.7</version>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.sonatype.central</groupId>
            <artifactId>central-publishing-maven-plugin</artifactId>
            <version>0.11.0</version>
            <extensions>true</extensions>
            <configuration>
              <publishingServerId>vanillabp-central</publishingServerId>
              <skipPublishing>${skip.central.release}</skipPublishing>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

