<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.tectonica</groupId>
    <artifactId>jonix-project</artifactId>
    <version>2022-08</version>
    <packaging>pom</packaging>

    <name>JONIX-PROJECT</name>
    <description>Maven configuration for Jonix sub-projects</description>
    <url>https://github.com/zach-m/jonix</url>

    <organization>
        <name>Tectonica Labs</name>
        <url>www.tectonica.co.il</url>
    </organization>

    <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>
            <name>Zach Melamed</name>
            <email>zach@tectonica.co.il</email>
            <organization>Tectonica Labs</organization>
            <organizationUrl>www.tectonica.co.il</organizationUrl>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/zach-m/jonix</url>
        <connection>scm:git:https://github.com/zach-m/jonix.git</connection>
    </scm>

    <modules>
        <module>jonix</module>
        <module>jonix-common</module>
        <module>jonix-xml</module>
        <module>jonix-onix2</module>
        <module>jonix-onix3</module>
        <module>jonix-json</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.slf4j>1.7.36</version.slf4j>
        <javadoc.bottom>Copyright &#169; 2012-2022 Zach Melamed. All rights reserved.</javadoc.bottom>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Configure compiler; this is used by IDEs, hence release 9 is the minimal value -->
                <!-- when installing and deploying, a special profile 'java8' below overrides the default -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.1</version>
                    <configuration>
                        <jdkToolchain>
                            <version>9</version>
                        </jdkToolchain>
                        <release>9</release>
                    </configuration>
                </plugin>

                <!-- Configure tester, and logging properties when running tests -->
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M7</version>
                    <configuration>
                        <systemProperties>
                            <property>
                                <name>java.util.logging.config.file</name>
                                <value>src/test/resources/logging.properties</value>
                            </property>
                        </systemProperties>
                    </configuration>
                </plugin>

                <!-- Configure javadocs generator -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.4.1</version>
                    <configuration>
                        <doctitle>Jonix Framework ${project.version} APIs</doctitle>
                        <windowtitle>Jonix ${project.version} APIs</windowtitle>
                        <encoding>UTF-8</encoding>
                        <excludePackageNames>repackaged</excludePackageNames>
                        <doclint>none</doclint>
                        <bottom>${javadoc.bottom}</bottom>
                    </configuration>
                </plugin>

                <!-- Configure various dependencies -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>4.0.0-M3</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.4.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>3.0.1</version>
                </plugin>
                <plugin>
                    <!-- mvn dependency:tree -->
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>

            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>3.3.9</version>
                                </requireMavenVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- CheckStyle plugin, set to execute on the verify phase.
                 To execute manually: mvn verify -DskipTests; and look for '*/target/checkstyle-result.xml' -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.2</version>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>8.41.1</version> <!-- when version changes, update IntelliJ.md -->
                    </dependency>
                </dependencies>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <failOnViolation>true</failOnViolation>
                    <violationSeverity>warning</violationSeverity>
                    <logViolationsToConsole>true</logViolationsToConsole>
                </configuration>
                <executions>
                    <execution>
                        <id>validate-checkstyle</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Generate aggregated javadocs for online deployment: mvn site -->
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-javadoc-plugin</artifactId>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <id>aggregated-javadoc</id>-->
<!--                        <phase>site</phase>-->
<!--                        <goals>-->
<!--                            <goal>aggregate</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--            </plugin>-->

        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <!-- Internal Projects -->
            <dependency>
                <groupId>com.tectonica</groupId>
                <artifactId>jonix</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.tectonica</groupId>
                <artifactId>jonix-common</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.tectonica</groupId>
                <artifactId>jonix-xml</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.tectonica</groupId>
                <artifactId>jonix-onix2</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.tectonica</groupId>
                <artifactId>jonix-onix3</artifactId>
                <version>${project.version}</version>
            </dependency>

            <!-- Logging -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${version.slf4j}</version>
            </dependency>

            <!-- JSON -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.12.6.1</version>
            </dependency>

            <!-- Testing -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-jdk14</artifactId>
                <version>${version.slf4j}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.tectonica</groupId>
                <artifactId>jonix-json</artifactId>
                <version>${project.version}</version>
                <scope>test</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <profiles>
        <!-- mvn -P versioning versions:set -DnewVersion=9.1 -->
        <!-- mvn -P versioning versions:display-plugin-updates -->
        <profile>
            <id>versioning</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>versions-maven-plugin</artifactId>
                        <version>2.11.0</version>
                        <configuration>
                            <generateBackupPoms>false</generateBackupPoms>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Java9 modularization (Jigsaw) within Java8 JARs -->
        <!-- mvn -P java8 clean package -->
        <profile>
            <id>java8</id>
            <build>
                <plugins>
                    <plugin>
                        <!-- We use a trick here, following official Maven documentation, having all java files
                             compiled twice. First compilation is with a Java9 compiler (module-info.java files
                             included), followed by a second compilation with a Java8 compiler for all but
                             module-info.java files), resulting in a JAR compatible with both Java8 and Java9.
                             This is needed only for installation and deployment of JAR files.
                             see: https://maven.apache.org/plugins/maven-compiler-plugin/examples/module-info.html -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <!-- first we compile all files for Java9 (ensures module-info contains right entries) -->
                            <!-- then, here we re-compile all files for Java8, except the module-info.java files -->
                            <execution>
                                <id>java8-compile</id>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <release>8</release>
                                    <excludes>
                                        <exclude>module-info.java</exclude>
                                    </excludes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Deployment configuration -->
        <!-- mvn -P java8,release clean deploy -->
        <profile>
            <id>release</id>

            <!-- Repository location -->
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
            </distributionManagement>

            <build>
                <plugins>

                    <!-- Generate source-code jars, set to run on verify phase -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.2.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Generate javadoc jars, set to run on verify phase -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadoc</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- GPG - needed for deployment -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- deployment to OSSRH -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>

    </profiles>
</project>
