Configure the execute goal of the GMaven plugin, reference the Groovy script in the source configuration for the execution. The following POM configures two executions of the execute goal referencing two scripts stored in ${basedir}/src/main/groovy.
<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>org.sonatype.mhandbook</groupId>
<artifactId>groovy-script-ex</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>groovy-script-ex</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>create-deps-file</id>
<phase>process-classes</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/main/groovy/CreateDeps.groovy</source>
</configuration>
</execution>
<execution>
<id>copy-the-source</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/main/groovy/CopySource.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>The CreateDeps.groovy script creates a file named deps.txt in ${basedir}/target/classes which contains a list of direct project dependencies, and the CopySource.groovy script copies the source from ${basedir}/src/main/java to ${basedir}/target/classes.
def depFile = new File(project.build.outputDirectory,
'deps.txt')
project.dependencies.each() {
depFile.write("${it.groupId}:${it.artifactId}:${it.version}")
}ant.copy(todir: project.build.outputDirectory ) {
fileset(dir: project.build.sourceDirectory)
}Written by Maven creator Jason Van Zyl and his team at Sonatype, Maven: The Definitive Guide clearly explains how this popular tool can bring order to your software development projects. The first part of the book demonstrates Maven's capabilities through the development of several sample applications from ideation to deployment, and the second part offers a complete reference guide. Concise and to the point, this is the only guide you need to manage your project.




Help









