<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) 2019, RTE (http://www.rte-france.com)
    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.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>

    <parent>
        <groupId>com.powsybl</groupId>
        <artifactId>powsybl</artifactId>
        <version>11</version>
    </parent>
    <artifactId>powsybl-parent</artifactId>
    <packaging>pom</packaging>

    <name>Powsybl Parent</name>
    <description>Powsybl Parent</description>

    <modules>
        <module>powsybl-parent-ws</module>
    </modules>

    <properties>
        <java.version>17</java.version>

        <maven.buildnumber.version>1.4</maven.buildnumber.version>
        <maven.checkstyle.version>3.1.1</maven.checkstyle.version>
        <maven.failsafe.version>2.22.2</maven.failsafe.version>
        <maven.gmavenplus.version>1.11.1</maven.gmavenplus.version>
        <!--
            For groovydoc, we must use the same version as the project's groovy version. Standardize on the groovy.version property.
            For projects which don't use groovy at all, this means the pluginmanagement will hold an invalid <version> definition
            (the literal string '${groovy.version}' instead of a valid version like '2.5.8') but this doesn't break the build.
            For projects which do use groovy (ie at least one submodule declares gmavenplus in their <build><plugins> element)
            then the build will break until either groovy.version or maven.groovydoc.version is set. It will break not just for the release profile
            so projects can detect errors early and fix their groovydoc configuration.
        -->
        <maven.groovydoc.version>${groovy.version}</maven.groovydoc.version>
        <maven.jacoco.version>0.8.8</maven.jacoco.version>
        <maven.javadoc.version>3.2.0</maven.javadoc.version>
        <maven.plugin.version>3.6.1</maven.plugin.version>
        <maven.shade.version>3.2.4</maven.shade.version>
        <maven.source.version>3.2.1</maven.source.version>
        <maven.templating.version>1.0.0</maven.templating.version>

        <!--
            by default don't override the javadocs. if you want to override the javadocs,
            set the following property in the project
            <properties>
                <groovydoc.classifier>javadoc</groovydoc.classifier>
                <groovydoc.groovyDocJavaSources>true</groovydoc.groovyDocJavaSources>
                <maven.javadoc.skip>true</maven.javadoc.skip>
            </properties>
        -->
        <groovydoc.classifier>groovydoc</groovydoc.classifier>
        <groovydoc.groovyDocJavaSources>false</groovydoc.groovyDocJavaSources>

        <sonar.exclusions>
            **/generated/**/*
        </sonar.exclusions>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>buildnumber-maven-plugin</artifactId>
                    <version>${maven.buildnumber.version}</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>create</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <doCheck>false</doCheck>
                        <doUpdate>false</doUpdate>
                        <revisionOnScmFailure>UNKNOWN_BUILD</revisionOnScmFailure>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${maven.failsafe.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.gmavenplus</groupId>
                    <artifactId>gmavenplus-plugin</artifactId>
                    <version>${maven.gmavenplus.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>addSources</goal>
                                <goal>addTestSources</goal>
                                <goal>generateStubs</goal>
                                <goal>compile</goal>
                                <goal>generateTestStubs</goal>
                                <goal>compileTests</goal>
                                <goal>removeStubs</goal>
                                <goal>removeTestStubs</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven.javadoc.version}</version>
                    <configuration>
                        <additionalOptions>-Xdoclint:none</additionalOptions>
                        <docfilessubdirs>true</docfilessubdirs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-plugin-plugin</artifactId>
                    <version>${maven.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>default-descriptor</id>
                            <phase>process-classes</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>${maven.shade.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>templating-maven-plugin</artifactId>
                    <version>${maven.templating.version}</version>
                    <executions>
                        <execution>
                            <id>filter-src</id>
                            <goals>
                                <goal>filter-sources</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>java9+</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <build>
                <!-- This is merged in the main configuration but plexus-compiler-javac is smart enough
                  to ignore the source and target arguments when the release argument is supplied. -->
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                <release>${java.version}</release>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>jacoco</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>${maven.jacoco.version}</version>
                        <configuration>
                            <excludes>
                                <!-- exclude generated classes -->
                                <exclude>**/generated/**/*</exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>checks</id>
            <activation>
                <property>
                    <name>powsybl.checks.skip</name>
                    <value>!true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>${maven.checkstyle.version}</version>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                                <configuration>
                                    <configLocation>powsybl-build-tools/checkstyle.xml</configLocation>
                                    <consoleOutput>true</consoleOutput>
                                    <failsOnError>true</failsOnError>
                                    <excludes>**/generated/**/*,**/module-info.java</excludes>
                                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                          <dependency>
                            <groupId>com.powsybl</groupId>
                            <artifactId>powsybl-build-tools</artifactId>
                            <version>11</version>
                          </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>${maven.javadoc.version}</version>
                        <executions>
                            <execution>
                                <id>javadoc-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>${maven.source.version}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                    <goal>test-jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.gmavenplus</groupId>
                            <artifactId>gmavenplus-plugin</artifactId>
                            <version>${maven.gmavenplus.version}</version>
                            <executions>
                                <execution>
                                    <id>groovydoc-jar</id>
                                    <goals>
                                        <goal>groovydoc-jar</goal>
                                    </goals>
                                    <configuration>
                                        <attach>false</attach>
                                        <includeClasspath>PROJECT_AND_PLUGIN</includeClasspath>
                                        <classifier>${groovydoc.classifier}</classifier>
                                        <groovyDocJavaSources>${groovydoc.groovyDocJavaSources}</groovyDocJavaSources>
                                    </configuration>
                                </execution>
                            </executions>
                            <dependencies>
                                <dependency>
                                    <groupId>org.codehaus.groovy</groupId>
                                    <artifactId>groovy-groovydoc</artifactId>
                                    <version>${maven.groovydoc.version}</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>build-helper-maven-plugin</artifactId>
                            <version>${maven.buildhelper.version}</version>
                            <executions>
                                <execution>
                                    <id>attach-artifact</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>attach-artifact</goal>
                                    </goals>
                                    <configuration>
                                        <artifacts>
                                            <artifact>
                                                <file>target/${project.artifactId}-${project.version}-${groovydoc.classifier}.jar</file>
                                                <type>javadoc</type>
                                                <classifier>${groovydoc.classifier}</classifier>
                                            </artifact>
                                        </artifacts>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
</project>
