<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>edu.byu.hbll.maven</groupId>
    <artifactId>parent</artifactId>
    <version>3.3.3</version>
  </parent>

  <artifactId>application-parent</artifactId>
  <name>Spring Boot Parent POM</name>
  <description>Parent POM for all Spring Boot projects</description>
  <packaging>pom</packaging>

  <properties>
    <spring-boot.version>2.1.4.RELEASE</spring-boot.version>
    <keycloak.version>4.8.2.Final</keycloak.version>
    <springfox.version>2.9.2</springfox.version>
    <frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
    <node.version>v10.15.0</node.version>
    <frontend.install.phase>none</frontend.install.phase>
    <frontend.package.phase>none</frontend.package.phase>
    <frontend.src.dir>${project.basedir}/src/main/angular</frontend.src.dir>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>edu.byu.hbll</groupId>
        <artifactId>json</artifactId>
        <version>1.4.0</version>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.keycloak.bom</groupId>
        <artifactId>keycloak-adapter-bom</artifactId>
        <version>${keycloak.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>

    <!-- spring-boot -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <!-- keycloak -->
    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-spring-boot-starter</artifactId>
    </dependency>

    <!-- swagger -->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>${springfox.version}</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>${springfox.version}</version>
    </dependency>

    <!-- include dependencies from executable-parent -->
    <dependency>
      <groupId>edu.byu.hbll.maven</groupId>
      <artifactId>executable-parent</artifactId>
      <version>3.3.3</version>
      <type>pom</type>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring-boot.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <additionalClasspathElements>
            <!-- https://github.com/spring-projects/spring-boot/issues/6254#issuecomment-281404852 -->
            <additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
          </additionalClasspathElements>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>${frontend-maven-plugin.version}</version>
        <configuration>
          <nodeVersion>${node.version}</nodeVersion>
          <workingDirectory>${frontend.src.dir}</workingDirectory>
          <installDirectory>${project.build.directory}</installDirectory>
        </configuration>
        <executions>
          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <phase>${frontend.install.phase}</phase>
          </execution>
          <execution>
            <id>npm install</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <phase>${frontend.install.phase}</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <id>angular-cli build</id>
            <configuration>
              <workingDirectory>${frontend.src.dir}</workingDirectory>
              <executable>node_modules/@angular/cli/bin/ng</executable>
              <arguments>
                <argument>build</argument>
                <argument>--prod</argument>
                <argument>--base-href</argument>
                <argument>/${frontend.contextRoot}/</argument>
              </arguments>
            </configuration>
            <phase>${frontend.package.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>position-angular-build</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>${frontend.package.phase}</phase>
            <configuration>
              <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
              <resources>
                <resource>
                  <directory>${frontend.src.dir}/dist/${frontend.name}</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
        <version>1.4.10</version>
        <configuration>
          <repository>${docker.repository}</repository>
          <buildArgs>
            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
          </buildArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
