<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>

    <!-- one-liner to take you to the cloud with settings form the application.yaml file: -->
    <!-- 'mvn clean package com.google.cloud.tools:jib-maven-plugin:dockerBuild -Dimage=distroless-hapi && docker run -p 8080:8080 distroless-hapi' -->
    <!--
    Note: HAPI projects use the "hapi-fhir" POM as their base to provide easy management.
    You do not need to use this in your own projects, so the "parent" tag and it's
    contents below may be removed
    if you are using this file as a basis for your own project.
    -->
    <parent>
        <groupId>ca.uhn.hapi.fhir</groupId>
        <artifactId>hapi-fhir</artifactId>
        <version>7.7.7-SNAPSHOT</version>
    </parent>

    <artifactId>hapi-fhir-jpaserver-starter</artifactId>
    <packaging>war</packaging>

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

    <prerequisites>
        <maven>3.8.3</maven>
    </prerequisites>

    <name>HAPI FHIR JPA Server - Starter Project</name>

    <repositories>
        <repository>
            <id>oss-snapshots</id>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </repository>
    </repositories>

    <dependencyManagement>
       <dependencies>

            <dependency>
               <groupId>org.glassfish.jaxb</groupId>
               <artifactId>jaxb-runtime</artifactId>
               <version>2.3.8</version>
           </dependency>
       </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
          <groupId>com.microsoft.sqlserver</groupId>
          <artifactId>mssql-jdbc</artifactId>
        </dependency>

        <!-- Needed for Email subscriptions -->
        <dependency>
            <groupId>org.simplejavamail</groupId>
            <artifactId>simple-java-mail</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>jakarta.annotation</groupId>
                    <artifactId>jakarta.annotation-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- This dependency includes the core HAPI-FHIR classes -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-base</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <!-- This dependency includes the EmailSenderImpl we will be using instead of standard javamail.-->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-jpaserver-subscription</artifactId>
            <version>${project.parent.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.zaxxer</groupId>
                    <artifactId>HikariCP-java7</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- This dependency includes the JPA server itself, which is packaged separately from the rest of HAPI FHIR -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-jpaserver-base</artifactId>
            <version>${project.parent.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jcl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- This dependency includes the JPA CQL Server -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-storage-cr</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <!-- This dependency includes the JPA MDM Server -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-jpaserver-mdm</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <!-- This dependency includes the CDS Hooks Server -->
        <dependency>
          <groupId>ca.uhn.hapi.fhir</groupId>
          <artifactId>hapi-fhir-server-cds-hooks</artifactId>
          <version>${project.parent.version}</version>
        </dependency>
        <!-- This dependency includes the OpenAPI Server -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-server-openapi</artifactId>
            <version>${project.parent.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.yaml</groupId>
                    <artifactId>snakeyaml</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- This dependency is used for the "FHIR Tester" web app overlay -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-testpage-overlay</artifactId>
            <version>${project.parent.version}</version>
            <type>war</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-testpage-overlay</artifactId>
            <version>${project.parent.version}</version>
            <classifier>classes</classifier>
        </dependency>
        <!-- This dependency is used to include the IPS Base Implementation -->
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-jpaserver-ips</artifactId>
            <version>${project.parent.version}</version>
        </dependency>

        <!-- HAPI-FHIR uses Logback for logging support. The logback library is included automatically by Maven as a part of the hapi-fhir-base dependency, but you also need to include a logging library. Logback
            is used here, but log4j would also be fine. -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
        </dependency>

        <!-- Needed for JEE/Servlet support -->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- If you are using HAPI narrative generation, you will need to include Thymeleaf as well. Otherwise the following can be omitted. -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
        </dependency>

        <!-- Used for CORS support -->
        <!-- Spring Web is used to deploy the server to a web container. -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <!-- commons-logging is provided by jcl-over-slf4j, and the jar often shows up because of transitive dependencies; this dependency should avoid it -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>

        <!-- You may not need this if you are deploying to an application server which provides database connection pools itself. -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- This example uses H2 embedded database. If you are using another database such as Mysql or Oracle, you may omit the following dependencies and replace them with an appropriate database client
            dependency for your database platform. -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <!-- webjars -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>Eonasdan-bootstrap-datetimepicker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars.bower</groupId>
            <artifactId>awesome-bootstrap-checkbox</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jstimezonedetect</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>select2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars.bower</groupId>
            <artifactId>jquery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars.bower</groupId>
            <artifactId>moment</artifactId>
        </dependency>

        <!-- The following dependencies are only needed for automated unit tests, you do not neccesarily need them to run the example. -->
        <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-jpaserver-test-utilities</artifactId>
            <version>${project.parent.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>elasticsearch</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>


        <!--
        For some reason JavaDoc crashed during site generation unless we have this dependency
        -->
        <dependency>
            <groupId>jakarta.interceptor</groupId>
            <artifactId>jakarta.interceptor-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-test-utilities</artifactId>
            <version>${project.parent.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.jetty.ee10</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.jetty.ee10.websocket</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.jetty.websocket</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>4.2.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>${spring_boot_version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>${spring_boot_version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-core -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
            <version>1.13.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>1.13.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus-simpleclient -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus-simpleclient</artifactId>
            <version>1.13.3</version>
        </dependency>


        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>5.0.1</version>
        </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.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.6.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.4.0</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <!-- Tells Maven to name the generated WAR file as ROOT.war -->
        <finalName>ROOT</finalName>

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!--
                    java -jar ROOT.war doesn't work; there is a bug in spring-boot-3.2.0 due to hibernate search,
                    probably solved in 3.2.1 https://github.com/spring-projects/spring-boot/issues/38585
                    (at the moment only tomcat works)
                    -->
                    <loaderImplementation>CLASSIC</loaderImplementation>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <mainClass>ca.uhn.fhir.jpa.starter.Application</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Tell Maven which Java source version you want to use -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <release>${java.version}</release>
                </configuration>
            </plugin>

            <!-- The configuration here tells the WAR plugin to include the FHIR Tester overlay. You can omit it if you are not using that feature. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Build-Time>${maven.build.timestamp}</Build-Time>
                        </manifestEntries>
                    </archive>
                    <attachClasses>true</attachClasses>
                    <overlays>
                        <overlay>
                            <groupId>ca.uhn.hapi.fhir</groupId>
                            <artifactId>hapi-fhir-testpage-overlay</artifactId>
                        </overlay>
                    </overlays>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

            <!-- This is to run the integration tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.4.0</version>
                <configuration>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.basepom.maven</groupId>
                <artifactId>duplicate-finder-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <inherited>true</inherited>
                    </execution>
                </executions>
                <configuration>
                    <failBuildInCaseOfConflict>false</failBuildInCaseOfConflict>
                    <checkTestClasspath>false</checkTestClasspath>
                    <!--
                    <printEqualFiles>false</printEqualFiles>
                    <failBuildInCaseOfDifferentContentConflict>true</failBuildInCaseOfDifferentContentConflict>
                    <failBuildInCaseOfEqualContentConflict>true</failBuildInCaseOfEqualContentConflict>
                    <failBuildInCaseOfConflict>true</failBuildInCaseOfConflict>
                    <checkCompileClasspath>true</checkCompileClasspath>
                    <checkRuntimeClasspath>false</checkRuntimeClasspath>
                    <skip>false</skip>
                    <quiet>false</quiet>
                    <preferLocal>true</preferLocal>
                    <useResultFile>true</useResultFile>
                    <resultFileMinClasspathCount>2</resultFileMinClasspathCount>
                    <resultFile>${project.build.directory}/duplicate-finder-result.xml</resultFile>
                    -->
                    <!--
                    <ignoredDependencies>
                        <dependency>
                            <groupId>javax.el</groupId>
                            <artifactId>javax.el-api</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>javax.mail</groupId>
                            <artifactId>javax.mail-api</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>javax.activation</groupId>
                            <artifactId>javax.activation-api</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>com.helger</groupId>
                            <artifactId>ph-schematron</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>commons-logging</groupId>
                            <artifactId>commons-logging</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.jscience</groupId>
                            <artifactId>jscience</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-jcl</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-jcl</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>com.google.code.findbugs</groupId>
                            <artifactId>annotations</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.derby</groupId>
                            <artifactId>derbyclient</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.derby</groupId>
                            <artifactId>derbynet</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.derby</groupId>
                            <artifactId>derbyclient</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.checkerframework</groupId>
                            <artifactId>checker-compat-qual</artifactId>
                        </dependency>
                    </ignoredDependencies>
                    -->
                    <ignoredResourcePatterns>
                        <ignoredResourcePattern>.*\.txt$</ignoredResourcePattern>
                        <ignoredResourcePattern>.*\.html$</ignoredResourcePattern>
                        <ignoredResourcePattern>config/favicon.ico</ignoredResourcePattern>
                    </ignoredResourcePatterns>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- Package the war for your preference. Use the boot profile if you prefer a single jar/war
        that can be started with and embedded application server. Default is jetty as it is assumed
        that the main users of this project already have an app server.
        Different profiles are needed as packing it for spring boot, makes the resulting war undeployable
        due to a class shading issue between tomcat and jetty.
        (the error is 'java.util.ServiceConfigurationError: org.apache.juli.logging.Log: org.eclipse.jetty.apache.jsp.JuliLog not a subtype')

         -->

        <!-- example of how to start the server using spring boot-->
        <!-- mvn clean package spring-boot:repackage -Pboot && java -jar target/ROOT.war -->

        <!-- Use the boot profile for development and debugging options when using your IDE -->
        <profile>
            <id>boot</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <version>${spring_boot_version}</version>
                </dependency>
            </dependencies>
        </profile>
        <!--                                                              -->
        <!-- Examples of how to run the server:                           -->
        <!--                                                              -->
        <!-- For Spring Boot use:                                         -->
        <!-- mvn spring-boot:run                                          -->
        <!--                                                              -->
        <!-- For JETTY use:                                               -->
        <!-- mvn -Pjetty spring-boot:run                                  -->
        <!--                                                              -->
        <!-- For the Tomcat WAR approach use:                             -->
        <!-- mvn clean package -DskipTests && java -jar ./target/ROOT.war -->
        <!--                                                              -->
        <!-- NEXT: Browse to http://localhost:8080/fhir                   -->
        <!--                                                              -->
        <profile>
            <id>jetty</id>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <version>${spring_boot_version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jetty</artifactId>
                    <version>${spring_boot_version}</version>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>ossrh-repo</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>deployToSonatype</name>
                </property>
            </activation>
            <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>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </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>
                                <configuration>
                                    <keyname>${gpg.keyname}</keyname>
                                    <passphraseServerId>${gpg.keyname}</passphraseServerId>
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- For connecting to GCP CloudSQL Postgres instances:
        https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/blob/main/docs/jdbc.md#postgres-1
        Needs 'boot' profile as well. -->
        <profile>
            <id>cloudsql-postgres</id>
            <dependencies>
                <dependency>
                    <groupId>com.google.cloud.sql</groupId>
                    <artifactId>postgres-socket-factory</artifactId>
                    <version>1.17.0</version>
                </dependency>
            </dependencies>
        </profile>       
    </profiles>
</project>
