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

    Copyright (c) 2023, 2025 Oracle and/or its affiliates.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>io.helidon.applications</groupId>
        <artifactId>helidon-applications-project</artifactId>
        <version>4.2.0</version>
    </parent>
    <groupId>io.helidon.applications</groupId>
    <artifactId>helidon-applications</artifactId>
    <packaging>pom</packaging>
    <name>Helidon Applications Parent</name>
    <description>Maven boilerplate for Helidon applications</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
        <maven.compiler.release>${maven.compiler.source}</maven.compiler.release>
        <version.plugin.compiler>3.11.0</version.plugin.compiler>
        <version.plugin.dependency>3.6.0</version.plugin.dependency>
        <version.plugin.exec>3.1.0</version.plugin.exec>
        <version.plugin.failsafe>3.1.2</version.plugin.failsafe>
        <version.plugin.helidon>4.0.16</version.plugin.helidon>
        <version.plugin.helidon-cli>4.0.16</version.plugin.helidon-cli>
        <version.plugin.jar>3.3.0</version.plugin.jar>
        <version.plugin.nativeimage>0.10.2</version.plugin.nativeimage>
        <version.plugin.os>1.5.0.Final</version.plugin.os>
        <version.plugin.protobuf>0.6.1</version.plugin.protobuf>
        <version.plugin.resources>3.3.1</version.plugin.resources>
        <version.plugin.surefire>3.1.0</version.plugin.surefire>
    </properties>

    <build>
        <finalName>${project.artifactId}</finalName>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>${version.plugin.os}</version>
            </extension>
        </extensions>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${version.plugin.compiler}</version>
                    <configuration>
                        <proc>full</proc>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${version.plugin.surefire}</version>
                    <configuration>
                        <useModulePath>false</useModulePath>
                        <systemPropertyVariables>
                            <java.util.logging.config.file>${project.build.outputDirectory}/logging.properties</java.util.logging.config.file>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${version.plugin.failsafe}</version>
                    <configuration>
                        <useModulePath>false</useModulePath>
                        <redirectTestOutputToFile>true</redirectTestOutputToFile>
                        <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>${version.plugin.dependency}</version>
                    <executions>
                        <execution>
                            <id>copy-libs</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/libs</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                                <overWriteIfNewer>true</overWriteIfNewer>
                                <includeScope>runtime</includeScope>
                                <!-- Hack to work-around https://github.com/square/okio/issues/1306 -->
                                <excludeArtifactIds>okio</excludeArtifactIds>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${version.plugin.resources}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${version.plugin.jar}</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>libs</classpathPrefix>
                                <!--suppress MavenModelInspection -->
                                <mainClass>${mainClass}</mainClass>
                                <useUniqueVersions>false</useUniqueVersions>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>${version.plugin.exec}</version>
                    <configuration>
                        <executable>java</executable>
                        <longClasspath>true</longClasspath>
                        <arguments>
                            <argument>-classpath</argument>
                            <classpath/>
                            <argument>${mainClass}</argument>
                        </arguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>io.helidon.build-tools</groupId>
                    <artifactId>helidon-maven-plugin</artifactId>
                    <version>${version.plugin.helidon}</version>
                    <dependencies>
                        <dependency>
                            <groupId>io.helidon.licensing</groupId>
                            <artifactId>helidon-licensing</artifactId>
                            <version>${helidon.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>io.helidon.build-tools</groupId>
                    <artifactId>helidon-cli-maven-plugin</artifactId>
                    <version>${version.plugin.helidon-cli}</version>
                </plugin>
                <plugin>
                    <groupId>org.xolstice.maven.plugins</groupId>
                    <artifactId>protobuf-maven-plugin</artifactId>
                    <version>${version.plugin.protobuf}</version>
                    <configuration>
                        <protocArtifact>com.google.protobuf:protoc:${version.lib.google-protobuf}:exe:${os.detected.classifier}</protocArtifact>
                        <pluginId>grpc-java</pluginId>
                        <pluginArtifact>io.grpc:protoc-gen-grpc-java:${version.lib.grpc}:exe:${os.detected.classifier}</pluginArtifact>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.graalvm.buildtools</groupId>
                    <artifactId>native-maven-plugin</artifactId>
                    <version>${version.plugin.nativeimage}</version>
                    <executions>
                        <execution>
                            <id>resource-config</id>
                            <phase>package</phase>
                            <configuration>
                                <!-- generate records for all module's resources -->
                                <isDetectionEnabled>true</isDetectionEnabled>
                            </configuration>
                        </execution>
                        <execution>
                            <id>build-native-image</id>
                            <phase>package</phase>
                            <configuration>
                                <!-- generate an argument file for native image - great for troubleshooting -->
                                <useArgFile>true</useArgFile>
                                <!-- this needs to be defined to have a single set of jars on classpath,
                                default approach would add classpath of module (from maven) and from jar (manifest) -->
                                <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                                <imageName>${project.build.finalName}</imageName>
                                <fallback>false</fallback>
                                <metadataRepository>
                                    <enabled>false</enabled>
                                </metadataRepository>
                                <buildArgs>
                                    <!-- Some native image features use the svm dependencies which require additional exports -->
                                    <arg>--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED</arg>
                                </buildArgs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>io.helidon.service</groupId>
                    <artifactId>helidon-service-project</artifactId>
                    <version>${helidon.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <profiles>
        <profile>
            <id>native-image-skip</id>
            <activation>
                <property>
                    <name>native.image.skip</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>resource-config</id>
                                <phase>none</phase>
                            </execution>
                            <execution>
                                <id>build-native-image</id>
                                <phase>none</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>native-image-static</id>
            <activation>
                <property>
                    <name>native.image.buildStatic</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build-native-image</id>
                                <configuration>
                                    <buildArgs combine.children="append">
                                        <arg>--static</arg>
                                    </buildArgs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>helidon-cli</id>
            <activation>
                <property>
                    <name>helidon.cli</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.helidon.build-tools</groupId>
                        <artifactId>helidon-cli-maven-plugin</artifactId>
                        <extensions>true</extensions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <!-- Remove the Helidon specific info from the effective pom. -->
    <url/>
    <scm>
        <connection/>
        <developerConnection/>
        <url/>
    </scm>
    <inceptionYear/>
    <organization/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <distributionManagement>
        <!--suppress MavenModelInspection -->
        <repository />
        <!--suppress MavenModelInspection -->
        <snapshotRepository />
    </distributionManagement>
</project>
