<?xml version="1.0" encoding="UTF-8"?>
<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>org.optaweb.vehiclerouting</groupId>
    <artifactId>optaweb-vehicle-routing</artifactId>
    <version>8.31.1.Final</version>
  </parent>

  <artifactId>optaweb-vehicle-routing-backend</artifactId>
  <packaging>jar</packaging>

  <name>OptaWeb Vehicle Routing Backend</name>

  <properties>
    <java.module.name>org.optaweb.vehiclerouting.backend</java.module.name>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

  <dependencies>
    <!-- Production dependencies -->
    <!-- Dataset YAML -->
    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-yaml</artifactId>
    </dependency>
    <!-- Persistence -->
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-hibernate-orm-panache</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jdbc-h2</artifactId>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <optional>true</optional>
    </dependency>
    <!-- Planner -->
    <dependency>
      <groupId>org.optaplanner</groupId>
      <artifactId>optaplanner-quarkus</artifactId>
    </dependency>
    <!-- TODO avoid guava if possible. -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>
    <!-- Region -->
    <dependency>
      <groupId>com.neovisionaries</groupId>
      <artifactId>nv-i18n</artifactId>
    </dependency>
    <!-- REST -->
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jackson</artifactId>
    </dependency>
    <!-- Routing -->
    <dependency>
      <groupId>com.graphhopper</groupId>
      <artifactId>graphhopper-reader-osm</artifactId>
    </dependency>
    <!--
      Add JAXB API dependency that's been deprecated in Java 9 and dropped in Java 11. See
      https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j.
    -->
    <dependency>
      <groupId>jakarta.xml.bind</groupId>
      <artifactId>jakarta.xml.bind-api</artifactId>
      <scope>runtime</scope>
    </dependency>
    <!-- Testing dependencies -->
    <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.mockito</groupId>
      <artifactId>mockito-junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.optaplanner</groupId>
      <artifactId>optaplanner-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5-mockito</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerArgs>
            <!--
              Visit https://docs.oracle.com/en/java/javase/11/tools/javac.html to learn more about javac warnings.
            -->
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-processing</arg>
            <arg>-Xlint:-serial</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${version.io.quarkus}</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
              <goal>generate-code</goal>
              <goal>generate-code-tests</goal>
            </goals>
            <configuration>
              <properties>
                <quarkus.package.output-directory>quarkus-app-h2</quarkus.package.output-directory>
                <quarkus.package.filter-optional-dependencies>true</quarkus.package.filter-optional-dependencies>
                <quarkus.package.included-optional-dependencies>com.h2database:h2::jar</quarkus.package.included-optional-dependencies>
              </properties>
            </configuration>
          </execution>
          <execution>
            <id>postgresql</id>
            <goals>
              <goal>build</goal>
            </goals>
            <configuration>
              <properties>
                <quarkus.profile>postgresql</quarkus.profile>
                <quarkus.package.output-directory>quarkus-app-postgresql</quarkus.package.output-directory>
                <quarkus.package.filter-optional-dependencies>true</quarkus.package.filter-optional-dependencies>
                <quarkus.package.included-optional-dependencies>org.postgresql:postgresql::jar</quarkus.package.included-optional-dependencies>
              </properties>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <show>package</show>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>mutationCoverage</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <version>1.4.3</version>
            <dependencies>
              <dependency>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-junit5-plugin</artifactId>
                <version>0.8</version>
              </dependency>
            </dependencies>
            <!--
              optaplanner-build-parent contains Pitest configuration that doesn't work well for this project
              and it's not possible to change it without a complete override (combine.self="override"),
              for example excludedClasses, timeoutConstant.
            -->
            <configuration>
              <reportsDirectory>local/pit-reports</reportsDirectory>
              <timestampedReports>true</timestampedReports>
              <!--
                Experimental. Using more than 2 threads doesn't reduce execution time further
                and leads to minion timeouts.
              -->
              <threads>2</threads>
              <mutators>
                <!-- See http://pitest.org/quickstart/mutators/ -->
                <mutator>DEFAULTS</mutator>
                <mutator>NON_VOID_METHOD_CALLS</mutator>
                <mutator>REMOVE_CONDITIONALS</mutator>
              </mutators>
              <avoidCallsTo>
                <!--
                  String concatenation ("a" + "b") is implemented using StringBuilder.append() in bytecode.
                  We're not interested in mutations of these calls - it's mostly toString() and exception messages.
                  Reducing number of mutations also improves execution time.
                -->
                <avoidCallsTo>java.lang.StringBuilder</avoidCallsTo>
                <avoidCallsTo>org.slf4j</avoidCallsTo>
              </avoidCallsTo>
              <excludedClasses>
                <excludedClass>*Config</excludedClass>
                <excludedClass>*Properties</excludedClass>
              </excludedClasses>
              <excludedMethods>hashCode</excludedMethods>
              <excludedTestClasses>
                <param>*IntegrationTest</param>
              </excludedTestClasses>
            </configuration>
            <executions>
              <execution>
                <id>default-pitest</id>
                <phase>verify</phase>
                <goals>
                  <goal>mutationCoverage</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemPropertyVariables>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <maven.home>${maven.home}</maven.home>
                  </systemPropertyVariables>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <quarkus.package.type>native</quarkus.package.type>
      </properties>
    </profile>
  </profiles>
</project>
