<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2011-2026 Lime Mojito Pty Ltd
  ~
  ~    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="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>
    <name>${project.artifactId}</name>

    <artifactId>jar-lambda-development</artifactId>
    <packaging>pom</packaging>

    <!--
        INSTRUCTIONS
        ============
        This project as parent, packaging as jar

        Supplies base lambda dependencies with Localstack and Lambda support for debugging in docker.
    -->

    <parent>
        <groupId>com.limemojito.oss.standards</groupId>
        <artifactId>jar-development</artifactId>
        <version>17.0.27</version>
        <relativePath>../jar-development</relativePath>
    </parent>

    <properties>
        <start-class>start-class property REQUIRED FOR PACKAGING FOR AWS</start-class>

        <!-- We have the shaded jar separate from the standard jar creation -->
        <build.shaded.jar.name>${project.artifactId}-${project.version}-aws.jar</build.shaded.jar.name>
        <shade.properties>${project.build.directory}/shade.properties</shade.properties>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-adapter-aws</artifactId>
        </dependency>
        <dependency>
            <groupId>com.limemojito.oss.standards.aws</groupId>
            <artifactId>lambda-utilities</artifactId>
            <version>17.0.27</version>
        </dependency>

        <dependency>
            <!-- Access primarily for LambdaSupport -->
            <groupId>com.limemojito.oss.test</groupId>
            <artifactId>test-utilities</artifactId>
            <version>17.0.27</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <!-- Access for LambdaSupport -->
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>lambda</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <!-- Access for LambdaSupport -->
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>s3</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>import-shade-properties</id>
                        <!-- This import occurs AFTER check-shade-file, so that we know the shade state -->
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${shade.properties}</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>check-shade-file</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <target>
                                <!-- Handle the strange bug where shade places a file on classes for empty project -->
                                <condition property="shade.file.present" else="false">
                                    <available file="${project.basedir}/target/classes"
                                               type="file"/>
                                </condition>
                                <!--suppress MavenModelInspection -->
                                <echo file="${shade.properties}"
                                      message="shade.file.present=${shade.file.present}"/>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>clean-classes</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>process-sources</phase>
                        <configuration>
                            <target if="shade.file.present">
                                <!-- Handle the strange bug where shade places a file on classes for empty project -->
                                <delete file="${project.basedir}/target/classes"/>
                                <delete dir="${project.basedir}/target/original-classes"/>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>clean-spring-jar</id>
                        <!-- on repeated builds, the spring repackage leaves an "original jar" that is not a boot jar. -->
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <delete file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
                                        quiet="true"/>
                                <delete file="${project.build.directory}/${build.shaded.jar.name}"
                                        quiet="true"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <MainClass>${start-class}</MainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <version>${spring.boot.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <shadedArtifactAttached>false</shadedArtifactAttached>
                            <outputFile>${project.build.directory}/${build.shaded.jar.name}</outputFile>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>${start-class}</mainClass>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer
                                        implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                                    <resource>META-INF/spring.factories</resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>
                                        META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
                                    </resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>
                                        META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports
                                    </resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.components</resource>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${build.shaded.jar.name}</file>
                                    <type>jar</type>
                                    <!-- This is known by CDK support and LambdaSupport -->
                                    <classifier>aws</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
