<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2018 the original author or the original authors
  ~
  ~ 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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>fr.myprysm.vertx</groupId>
    <artifactId>vertx-parent</artifactId>
    <name>${project.groupId}:${project.artifactId}</name>
    <version>0.1.2</version>
    <description>Parent project for Myprysm Vert.x projects</description>
    <packaging>pom</packaging>
    <url>https://github.com/myprysm/vertx-utils/vertx-parent</url>
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <properties>
        <stack.version>0.1.2</stack.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <vertx.version>3.5.2</vertx.version>
        <logback.version>1.2.3</logback.version>
        <guava.version>25.0-jre</guava.version>
        <lombok.version>1.16.20</lombok.version>
        <commons-lang.version>3.7</commons-lang.version>
        <classpath-scanner.version>2.18.1</classpath-scanner.version>

        <assertj.version>3.9.0</assertj.version>
        <junit-jupiter.version>5.1.0</junit-jupiter.version>
        <junit-platform.version>1.1.0</junit-platform.version>

        <!-- plugin versions & properties -->
        <source-plugin.version>3.0.1</source-plugin.version>
        <jar-plugin.version>3.1.0</jar-plugin.version>
        <compiler-plugin.version>3.5.1</compiler-plugin.version>
        <docker-plugin.version>1.0.0</docker-plugin.version>
        <shade-plugin.version>2.4.3</shade-plugin.version>
        <clean-plugin.version>3.0.0</clean-plugin.version>
        <surefire-plugin.version>2.19.1</surefire-plugin.version>
        <jacoco-plugin.version>0.8.0</jacoco-plugin.version>
        <javadoc-plugin.version>3.0.0</javadoc-plugin.version>
        <site-plugin.version>3.7</site-plugin.version>
        <gpg-plugin.version>1.6</gpg-plugin.version>
        <nexus-plugin.version>1.6.8</nexus-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-codegen</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-lang-kotlin</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Disabled at the moment as it clashes with classpath scanner -->
        <!--<dependency>-->
        <!--<groupId>io.vertx</groupId>-->
        <!--<artifactId>vertx-lang-scala_2.12</artifactId>-->
        <!--&lt;!&ndash;Not provided by Vert.x BOM&ndash;&gt;-->
        <!--<version>${vertx.version}</version>-->
        <!--<scope>provided</scope>-->
        <!--</dependency>-->
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-lang-groovy</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-lang-ruby</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-lang-ceylon</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-lang-js</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${logback.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons-lang.version}</version>
            </dependency>
            <dependency>
                <groupId>io.github.lukehutch</groupId>
                <artifactId>fast-classpath-scanner</artifactId>
                <version>${classpath-scanner.version}</version>
            </dependency>

            <dependency>
                <groupId>io.vertx</groupId>
                <artifactId>vertx-junit5</artifactId>
                <version>${vertx.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <version>${assertj.version}</version>
                <scope>test</scope>
            </dependency>
            <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.platform</groupId>
                <artifactId>junit-platform-engine</artifactId>
                <version>${junit-platform.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-launcher</artifactId>
                <version>${junit-platform.version}</version>
                <scope>test</scope>
            </dependency>


            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
            </dependency>

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>io.vertx</groupId>
                <artifactId>vertx-dependencies</artifactId>
                <version>${vertx.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${source-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                            <goal>test-jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${jar-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-test-jar</id>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Docker plugin disabled by default, modules have to add it to package phase -->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>docker</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${compiler-plugin.version}</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <useIncrementalCompilation>false</useIncrementalCompilation>

                        <!-- Codegen -->
                        <annotationProcessors>
                            <!-- Lombok annotation processor in the chain to allow Vert.x codegen to work -->
                            <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor
                            </annotationProcessor>
                            <annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
                        </annotationProcessors>
                        <generatedSourcesDirectory>${project.basedir}/src/main/generated</generatedSourcesDirectory>
                        <compilerArgs>
                            <arg>-Acodegen.output=${project.basedir}/src/main</arg>
                        </compilerArgs>

                    </configuration>
                </plugin>

                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>${clean-plugin.version}</version>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>${project.basedir}/src/main/generated</directory>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>${docker-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>docker</id>
                            <phase>package</phase>
                            <goals>
                                <goal>build</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <!-- Configure the image name -->
                        <imageName>myprysm/${project.artifactId}:latest</imageName>
                        <baseImage>openjdk:8-jre-alpine</baseImage>
                        <env>
                            <JAR_NAME>${project.artifactId}-fat.jar</JAR_NAME>
                            <VERTICLE_HOME>/usr/verticles</VERTICLE_HOME>
                        </env>
                        <workdir>$VERTICLE_HOME</workdir>
                        <resources>
                            <resource>
                                <targetPath>/usr/verticles</targetPath>
                                <directory>${project.build.directory}</directory>
                                <includes>
                                    <include>${project.artifactId}-fat.jar</include>
                                </includes>
                            </resource>
                            <!-- don't forget to also add all the dependencies required by your application -->
                        </resources>

                        <entryPoint>["sh", "-c"]</entryPoint>
                        <cmd><![CDATA[
["exec java -XX:+PrintFlagsFinal $JAVA_OPTIONS -Dvertx.metrics.options.enabled=true -Dvertx.metrics.options.jmxEnabled=true -jar $JAR_NAME -cp ."]
                        ]]></cmd>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>${shade-plugin.version}</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <filters>
                                    <filter>
                                        <artifact>*:*</artifact>
                                        <excludes>
                                            <exclude>META-INF/*.SF</exclude>
                                            <exclude>META-INF/*.DSA</exclude>
                                            <exclude>META-INF/*.RSA</exclude>
                                        </excludes>
                                    </filter>
                                </filters>
                                <transformers>
                                    <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <manifestEntries>
                                            <Main-Class>fr.myprysm.pipeline.Launcher</Main-Class>
                                            <Main-Verticle>fr.myprysm.pipeline.DeploymentVerticle</Main-Verticle>
                                        </manifestEntries>
                                    </transformer>
                                    <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
                                    </transformer>
                                </transformers>
                                <artifactSet>
                                </artifactSet>
                                <outputFile>${project.build.directory}/${project.artifactId}-fat.jar
                                </outputFile>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${surefire-plugin.version}</version>
                    <configuration>
                        <!-- Sets the vm arguments for JaCoCO instrumentation -->
                        <argLine>${surefireArgLine}</argLine>
                        <includes>
                            <include>**/Test*.java</include>
                            <include>**/*Test.java</include>
                            <include>**/*Tests.java</include>
                            <include>**/*TestCase.java</include>
                            <include>**/RandomName.java</include>
                        </includes>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.junit.platform</groupId>
                            <artifactId>junit-platform-surefire-provider</artifactId>
                            <version>${junit-platform.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>

                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                                <propertyName>surefireArgLine</propertyName>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-unit-test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                                <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <excludes>
                            <exclude>**/*VertxEBProxy.*</exclude>
                            <exclude>**/*VertxProxyHandler.*</exclude>
                            <exclude>**/*Converter.*</exclude>
                            <exclude>**/groovy/**</exclude>
                        </excludes>
                    </configuration>
                </plugin>


                <!-- Plugins for site phase -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>${site-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>attach-site</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>site-and-stage</id>
                            <phase>site</phase>
                            <goals>
                                <goal>site</goal>
                                <goal>stage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- sources -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>${source-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                                <goal>test-jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!-- Doc & report -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${javadoc-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>javadoc</id>
                            <goals>
                                <goal>javadoc</goal>
                            </goals>
                            <phase>package</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <failOnError>false</failOnError>
                    </configuration>
                </plugin>

                <!-- sonatype to push artifact to maven central -->
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>${nexus-plugin.version}</version>
                    <extensions>true</extensions>
                    <configuration>
                        <serverId>ossrh</serverId>
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                        <autoReleaseAfterClose>false</autoReleaseAfterClose>
                    </configuration>
                </plugin>

                <!-- Sign the artifacts -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>${gpg-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>docker</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Builds the image with cluster mode activated -->
        <profile>
            <id>cluster</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <!-- Allows to provide memory settings through env with docker/kubernetes -->
                            <cmd><![CDATA[
["exec java -XX:+PrintFlagsFinal $JAVA_OPTIONS -Dvertx.metrics.options.enabled=true -Dvertx.metrics.options.jmxEnabled=true -jar $JAR_NAME -cp -cluster ."]
                        ]]></cmd>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <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>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                    </plugin>

                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <developers>
        <developer>
            <name>Damien Benon</name>
            <url>https://github.com/myprysm</url>
        </developer>
    </developers>
    <scm>
        <url>https://github.com/myprysm/vertx-utils/vertx-parent</url>
    </scm>


    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>
</project>