<?xml version="1.0"?>
<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>

    <name>SBL - Common Maven configuration</name>
    <description>
        This is a common root POM for many NAV projects. It defines versions of core plugins,
        configuration of code quality metrics, CI server URLs, and distribution management
        for artifact deploys.
    </description>
    <url>https://github.com/navikt/common-java-modules</url>

    <groupId>no.nav.common</groupId>
    <artifactId>mor-pom</artifactId>
    <version>1.2019.04.30-17.04-3d8bebacf430</version>
    <packaging>pom</packaging>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/licenses/MIT</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <organization>NAV (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration
            </organization>
            <organizationUrl>https://www.nav.no</organizationUrl>
        </developer>
    </developers>

    <modules>
        <module>abac</module>
        <module>aktor-klient</module>
        <module>api-app</module>
        <module>app-mock</module>
        <module>auth</module>
        <module>auth-openam-sbs</module>
        <module>batch</module>
        <module>bom</module>
        <module>cache</module>
        <module>cxf</module>
        <module>fasit</module>
        <module>feature-toggle</module>
        <module>feed</module>
        <module>jdbc</module>
        <module>jetty</module>
        <module>json</module>
        <module>log</module>
        <module>leader-election</module>
        <module>metrics</module>
        <module>oidc-security</module>
        <module>pact-fo</module>
        <module>rest</module>
        <module>selftest</module>
        <module>smoketest</module>
        <module>suspend</module>
        <module>test</module>
        <module>test-config</module>
        <module>time</module>
        <module>types</module>
        <module>util</module>
        <module>web</module>
        <module>validation</module>
        <module>yaml</module>
    </modules>

    <prerequisites>
        <maven>3.0.4</maven>
    </prerequisites>

    <properties>

        <!-- unntak fra bom-versjonering siden vi gjør oppsett i denne pommen -->
        <junit.jupiter.version>5.1.1</junit.jupiter.version>
        <junit.platform.version>1.1.1</junit.platform.version>
        <junit.vintage.version>5.1.1</junit.vintage.version>


        <java.jdk.version>1.8</java.jdk.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <checkstyle.config.location>codestyle/nav-mod/checkstyle.xml</checkstyle.config.location>
        <pmd.config.location>codestyle/nav-mod/pmd.xml</pmd.config.location>
        <findbugs.config.location>codestyle/nav-mod/findbugs.xml</findbugs.config.location>

        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.jacoco.reportPaths>${user.dir}/target/jacoco.exec</sonar.jacoco.reportPaths>
    </properties>

    <dependencies>
        <!-- tilgjengeliggjør riktig versjon i test-scope slik at junit5-tester kjører i intellij -->
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>${junit.platform.version}</version>
            <scope>test</scope>
        </dependency>

        <!--
        slik at vi unngår "groups/excludedGroups require TestNG or JUnit48+ on project test classpath" for prosjekter
        som kun bruker junit5
         -->
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit.vintage.version}</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>

                <!-- CORE PLUGINS -->

                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.6.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.jdk.version}</source>
                        <target>${java.jdk.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.4</version>
                </plugin>
                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.18</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.5</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <attachClasses>true</attachClasses>
                        <archive>
                            <manifest>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.10.1</version>
                    <configuration>
                        <version>7</version>
                        <defaultLibBundleDir>lib</defaultLibBundleDir>
                        <encoding>${project.build.sourceEncoding}</encoding>
                        <archive>
                            <manifest>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>

                <plugin>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.2</version>
                    <configuration>
                        <goals>deploy</goals>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                    </configuration>
                </plugin>

                <!-- QUALITY ASSURANCE PLUGINS -->

                <plugin>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>2.13</version>
                    <configuration>
                        <configLocation>${checkstyle.config.location}</configLocation>
                        <violationSeverity>info</violationSeverity>
                        <logViolationsToConsole>true</logViolationsToConsole>
                        <linkXRef>false</linkXRef>
                        <failOnViolation>false</failOnViolation>
                        <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>no.nav</groupId>
                            <artifactId>java-codestyle</artifactId>
                            <version>1.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <targetJdk>${java.jdk.version}</targetJdk>
                        <rulesets>
                            <ruleset>${pmd.config.location}</ruleset>
                        </rulesets>
                        <minimumTokens>40</minimumTokens>
                        <aggregate>true</aggregate>
                        <linkXRef>false</linkXRef>
                        <includeTests>true</includeTests>
                        <failOnViolation>false</failOnViolation>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>no.nav</groupId>
                            <artifactId>java-codestyle</artifactId>
                            <version>1.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
                        <includeFilterFile>${findbugs.config.location}</includeFilterFile>
                        <findbugsXmlOutput>true</findbugsXmlOutput>
                        <failOnError>true</failOnError>
                        <xmlOutput>true</xmlOutput>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>no.nav</groupId>
                            <artifactId>java-codestyle</artifactId>
                            <version>1.0</version>
                        </dependency>
                    </dependencies>
                </plugin>

                <!-- AUXILIARY PLUGINS -->

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                        <additionalConfig>
                            <file>
                                <name>.settings/org.eclipse.core.resources.prefs</name>
                                <content>
                                    <![CDATA[eclipse.preferences.version=1
                                    <![CDATA[eclipse.preferences.version=1
                                    encoding/<project>=${project.build.sourceEncoding}]]>
                                </content>
                            </file>
                        </additionalConfig>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>1.3.1</version>
                    <executions>
                        <execution>
                            <id>validate-dependencies</id>
                            <goals>
                                <goal>enforce</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <dependencyConvergence/>
                                </rules>
                                <fail>true</fail>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>analyze</id>
                        <goals>
                            <goal>analyze-only</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>analyze-pom</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>analyze-dep-mgt</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <failBuild>true</failBuild>
                    <ignoreDirect>false</ignoreDirect>
                    <ignoredUsedUndeclaredDependencies>
                        <!--
                        This deactivates the requirement of declaring every used dependency in a project's pom.
                        We are omitting this, even though it its considered best practice, because:

                        - enforced management of transitive dependencies increases the likelihood of management errors
                          that may cause diamonds of death, which often results in nasty runtime errors. Even having decent
                          test coverage over the affected dependencies may not detect such errors due to the indeterministic
                          nature of classloading in different contexts (different OSes, JVMs, build tools, packaging formats)

                        - the main motivation of the requirement seems to be avoiding compile errors when a change of a
                          direct dependency causes a change in transitive dependencies. A transitive dependency might for
                          instance be eliminated and must be added as a direct dependency instead.

                        Since compile errors generally are easier to detect and fix than runtime error, we should try to minimize
                        the risk of having runtime errors by being allowed to use a dependency transitively when it makes sense.

                        -->
                        <ignoredUsedUndeclaredDependency>*</ignoredUsedUndeclaredDependency>
                    </ignoredUsedUndeclaredDependencies>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <configuration>
                    <destFile>${sonar.jacoco.reportPaths}</destFile>
                    <append>true</append>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>jacoco.agent.argLine</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>pre-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <!-- tilgjengeliggjør junit5 for surefire slik at slike tester kjøres  -->
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>${junit.platform.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                        <version>${junit.vintage.version}</version>
                    </dependency>
                </dependencies>
                <configuration>

                    <!-- Ellers vil maven kun kjøre tester som slutter på 'Test' (!) -->
                    <includes>
                        <include>*</include>
                    </includes>

                    <!--
                     NB:
                     @Category (junit4) fungerer ikke i kombinasjon med junit-platform-surefire-provider
                     Løsningen er å skrive smoketester i junit5 med @Tag
                     -->
                    <properties>
                        <excludeTags>smoketest</excludeTags>
                    </properties>

                    <!--suppress MavenModelInspection -->
                    <argLine>${jacoco.agent.argLine} -Xmx2g</argLine>

                    <!--
                     maven-surefire default er forkCount=1 + reuseForks=true
                     dvs at surefire vil kjøre alle testene i en og samme jvm pr maven-modul
                    -->
                    <reuseForks>false
                    </reuseForks> <!-- fører til at hver test-klasse kjøres i egen jvm. Dermed oppnår vi bedre isolasjon mellom potensielt skjøre tester, som kan finne på å mutere på global state etc -->

                    <!-- fjerner edge-caser ved nøstede classloadere, som f.eks. hvis man tester med jetty -->
                    <useSystemClassLoader>false</useSystemClassLoader>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.9.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <useReleaseProfile>true</useReleaseProfile>
                    <releaseProfiles>release</releaseProfiles>
                    <goals>deploy</goals>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.8</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>deploy</phase>
                        <!-- By default, this is the phase deploy goal will bind to -->
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    <serverId>ossrh</serverId>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>smoketest</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <properties>
                                <includeTags>smoketest</includeTags>
                                <excludeTags>overskriv_default_exclude_tags</excludeTags>
                            </properties>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>lokal</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <properties>
                                <excludeTags>no.nav.sbl.dialogarena.test.junit.VirkerIkkeLokaltCategory</excludeTags>
                            </properties>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-source-plugin</artifactId>
                        <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-javadoc-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <scm>
        <developerConnection>scm:git:git@github.com:navikt/common-java-modules.git</developerConnection>
        <connection>scm:git:git@github.com:navikt/common-java-modules.git</connection>
        <url>https://github.com/navikt/common-java-modules</url>
        <tag>HEAD</tag>
    </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>

    <ciManagement>
        <system>travis</system>
        <url>https://travis-ci.org/navikt/common-java-modules</url>
    </ciManagement>

</project>
