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

    Copyright (c) 2023-2024 Maveniverse Org.
    All rights reserved. This program and the accompanying materials
    are made available under the terms of the Eclipse Public License v2.0
    which accompanies this distribution, and is available at
    https://www.eclipse.org/legal/epl-v20.html

-->
<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>eu.maveniverse.maven.nisse</groupId>
    <artifactId>nisse</artifactId>
    <version>0.9.2</version>
  </parent>

  <groupId>eu.maveniverse.gradle.plugins</groupId>
  <artifactId>nisse-gradle-plugin</artifactId>
  <packaging>pom</packaging>

  <name>${project.groupId}:${project.artifactId}</name>

  <properties>
    <version.toolrunner>0.2.4</version.toolrunner>
    <localRepository>${project.build.directory}/local-repo</localRepository>
    <gradleTask>build</gradleTask>
  </properties>

  <dependencies>
    <dependency>
      <groupId>eu.maveniverse.maven.nisse</groupId>
      <artifactId>core</artifactId>
    </dependency>
    <dependency>
      <groupId>eu.maveniverse.maven.nisse.sources</groupId>
      <artifactId>jgit-source</artifactId>
    </dependency>
    <dependency>
      <groupId>eu.maveniverse.maven.nisse.sources</groupId>
      <artifactId>os-source</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${project.basedir}/.gradle</directory>
            </fileset>
            <fileset>
              <directory>${project.basedir}/gradle</directory>
            </fileset>
            <fileset>
              <directory>${project.basedir}/build</directory>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-invoker-plugin</artifactId>
        <executions>
          <execution>
            <id>create-local-repository</id>
            <goals>
              <goal>install</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <localRepositoryPath>${localRepository}</localRepositoryPath>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>eu.maveniverse.maven.plugins</groupId>
        <artifactId>toolrunner</artifactId>
        <version>${version.toolrunner}</version>
        <dependencies>
          <dependency>
            <groupId>eu.maveniverse.maven.toolrunner.tools</groupId>
            <artifactId>gradle</artifactId>
            <version>${version.toolrunner}</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>gradle-build</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <toolName>gradle</toolName>
              <toolVersion>9.5.1</toolVersion>
              <allowPathDetection>true</allowPathDetection>
              <isTransient>true</isTransient>
              <arguments>
                <argument>--no-daemon</argument>
                <argument>-PmavenProjectVersion=${project.version}</argument>
                <argument>-PmavenLocalRepository=${localRepository}</argument>
                <argument>${gradleTask}</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-gradle-plugin</id>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.basedir}/build/libs/nisse-gradle-plugin-${project.version}.jar</file>
                  <type>jar</type>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>maveniverse-release</id>
      <properties>
        <gradleTask>publishPlugins</gradleTask>
      </properties>
    </profile>
  </profiles>
</project>
