<?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>dev.morphia.critter</groupId>
        <artifactId>build-tools</artifactId>
        <version>4.4.4</version>
    </parent>

    <artifactId>dev.morphia.critter.gradle.plugin</artifactId>
    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>dev.morphia.critter</groupId>
            <artifactId>critter-generator</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.3</version>
                <executions>
                    <execution>
                        <id>build.gradle</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filesToInclude>${project.basedir}/build.gradle.kts, ${project.basedir}/gradle.properties, ${project.basedir}/gradle/wrapper/gradle-wrapper.properties</filesToInclude>
                    <replacements>
                        <replacement>
                            <token>(classpath\("org.apache.maven:maven-model.*)</token>
                            <value>classpath("org.apache.maven:maven-model:${maven.version}")</value>
                        </replacement>
                        <replacement>
                            <token>(kotlin\("jvm"\).*)</token>
                            <value>kotlin("jvm") version "${kotlin.version}"</value>
                        </replacement>
                        <replacement>
                            <token>distributionUrl=.*</token>
                            <value>distributionUrl=https\\://services.gradle.org/distributions/gradle-${gradle.version}-bin.zip</value>
                        </replacement>
                    </replacements>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                    <!-- Replacing default-testCompile as it is treated specially by maven -->
                    <execution>
                        <id>default-testCompile</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <workingDirectory>${project.basedir}</workingDirectory>
                            <arguments>
                                <argument>-cp</argument>
                                <argument>gradle/wrapper/gradle-wrapper.jar</argument>
                                <argument>org.gradle.wrapper.GradleWrapperMain</argument>
                                <argument>classes</argument>
                            </arguments>
                            <useMavenLogger>true</useMavenLogger>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <workingDirectory>${project.basedir}</workingDirectory>
                            <arguments>
                                <argument>-cp</argument>
                                <argument>gradle/wrapper/gradle-wrapper.jar</argument>
                                <argument>org.gradle.wrapper.GradleWrapperMain</argument>
                                <argument>classes</argument>
                            </arguments>
                            <useMavenLogger>true</useMavenLogger>
                        </configuration>
                    </execution>
                    <execution>
                        <id>clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <workingDirectory>${project.basedir}</workingDirectory>
                            <arguments>
                                <argument>-cp</argument>
                                <argument>gradle/wrapper/gradle-wrapper.jar</argument>
                                <argument>org.gradle.wrapper.GradleWrapperMain</argument>
                                <argument>clean</argument>
                            </arguments>
                            <useMavenLogger>true</useMavenLogger>
                        </configuration>
                    </execution>
                    <execution>
                        <id>gradle</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <workingDirectory>${project.basedir}</workingDirectory>
                            <arguments>
                                <argument>-cp</argument>
                                <argument>gradle/wrapper/gradle-wrapper.jar</argument>
                                <argument>org.gradle.wrapper.GradleWrapperMain</argument>
                                <argument>assemble</argument>
                                <argument>-S</argument>
                                <argument>--stacktrace</argument>
                                <argument>--no-daemon</argument>
                            </arguments>
                            <useMavenLogger>true</useMavenLogger>
                        </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>build/libs/critter-gradle-${project.version}.jar</file>
                                    <type>jar</type>
                                </artifact>
                                <artifact>
                                    <file>build/libs/critter-gradle-${project.version}-javadoc.jar</file>
                                    <type>jar</type>
                                    <classifier>javadoc</classifier>
                                </artifact>
                                <artifact>
                                    <file>build/libs/critter-gradle-${project.version}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
