<!--
  #%L
  %%
  Copyright (C) 2019 BMW Car IT GmbH
  %%
  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.
  #L%
  -->
<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>io.joynr.tools.generator</groupId>
	<artifactId>joynr-generator-gradle-plugin</artifactId>
	<packaging>maven-plugin</packaging>
	<name>${project.groupId}:${project.artifactId}</name>

	<parent>
		<groupId>io.joynr.tools</groupId>
		<artifactId>generator</artifactId>
		<version>1.18.2</version>
		<relativePath>../pom.xml</relativePath>
	</parent>

	<properties>
		<version.plugin.antrun>1.8</version.plugin.antrun>
		<version.plugin.compiler>3.8.1</version.plugin.compiler>
		<version.gradle>6.1.1</version.gradle>
		<exec.gradle>gradlew</exec.gradle>
	</properties>

	<repositories>
		<repository>
			<id>google-maven</id>
			<url>https://maven.google.com/</url>
		</repository>
	</repositories>		

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-dependency-plugin</artifactId>
					<executions>
						<execution>
							<id>analyze</id>
							<goals>
								<goal>analyze-only</goal>
							</goals>
							<configuration>
								<ignoredUnusedDeclaredDependencies>
									<ignoredUnusedDeclaredDependency>org.jetbrains.kotlin:kotlin-stdlib-jdk8</ignoredUnusedDeclaredDependency>
									<ignoredUnusedDeclaredDependency>io.joynr.tools.generator:generator-framework</ignoredUnusedDeclaredDependency>
									<ignoredUnusedDeclaredDependency>io.joynr.tools.generator:java-generator</ignoredUnusedDeclaredDependency>
									<ignoredUnusedDeclaredDependency>com.android.tools.build:gradle</ignoredUnusedDeclaredDependency>
									<ignoredUnusedDeclaredDependency>org.antlr:antlr-runtime</ignoredUnusedDeclaredDependency>
								</ignoredUnusedDeclaredDependencies>
							</configuration>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<!-- The Gradle plugin must be built by Gradle; therefore the compilation is skipped. -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>${version.plugin.compiler}</version>
				<configuration>
					<skipMain>true</skipMain>
					<skip>true</skip>
				</configuration>
			</plugin>

			<!-- We need this plugin to circumvent the issue regarding the lack of descriptor
			otherwise the build fails -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-plugin-plugin</artifactId>
				<configuration>
					<!-- see https://issues.apache.org/jira/browse/MNG-5346 -->
					<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
				</configuration>

				<executions>
					<execution>
						<id>mojo-descriptor</id>
						<goals>
							<goal>descriptor</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<artifactId>exec-maven-plugin</artifactId>
				<groupId>org.codehaus.mojo</groupId>
				<executions>
					<!-- Match the maven clean phase with the gradle clean -->
					<execution>
						<id>gradle-clean</id>
						<phase>clean</phase>
						<goals>
							<goal>exec</goal>
						</goals>
						<configuration>
							<executable>${basedir}/${exec.gradle}</executable>
							<arguments>
								<argument>clean</argument>
								<argument>--info</argument>
							</arguments>
						</configuration>
					</execution>

					<!-- Match the maven compile phase with the gradle compile -->
					<execution>
						<id>gradle-build</id>
						<phase>compile</phase>
						<goals>
							<goal>exec</goal>
						</goals>
						<configuration>
							<executable>${basedir}/${exec.gradle}</executable>
							<arguments>
								<argument>build</argument>
							</arguments>
						</configuration>
					</execution>

					<!-- When maven install to the local repo, trigger the gradle to have the
					correct configurations  -->
					<execution>
						<id>gradle-publish-local</id>
						<phase>install</phase>
						<goals>
							<goal>exec</goal>
						</goals>
						<configuration>
							<executable>${basedir}/${exec.gradle}</executable>
							<arguments>
								<argument>publishToMavenLocal</argument>
								<argument>--info</argument>
							</arguments>
						</configuration>
					</execution>

				</executions>
			</plugin>

			<!-- Copies the artifact created by Gradle back to the Maven target folder. -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>${version.plugin.antrun}</version>
				<executions>
					<execution>
						<id>copy-jar</id>
						<phase>package</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<copy file="${project.basedir}/build/libs/${project.artifactId}-${project.version}.jar" todir="${project.build.directory}" overwrite="true" />
							</target>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

	<!-- These dependencies are a clone of the ones on the build.gradle file.
	 These are just for deployment purpose only, the real dependencies are on the build.gradle file -->
	<dependencies>
		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-stdlib-jdk8</artifactId>
			<version>1.3.61</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>io.joynr.tools.generator</groupId>
			<artifactId>generator-framework</artifactId>
			<version>${project.version}</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>io.joynr.tools.generator</groupId>
			<artifactId>java-generator</artifactId>
			<version>${project.version}</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>com.android.tools.build</groupId>
			<artifactId>gradle</artifactId>
			<version>4.0.0</version>
		</dependency>
		<dependency>
			<groupId>org.antlr</groupId>
			<artifactId>antlr-runtime</artifactId>
			<version>3.2</version>
			<scope>runtime</scope>
		</dependency>
	</dependencies>

</project>
