MÄR 2010
GMaven configuration for groovy and java projects
How to configure a maven project that contains groovy sources? I found serveral web pages, but most of them with old and obsolete documentation.
Here is how it is working for my project.
The maven pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Generated from archetype; please customize.
-->
<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>viaboxx</groupId>
<artifactId>gmaven-example</artifactId>
<name>Example Project</name>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo1 gmaven</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo1 gmaven</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.2</version>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
<executions>
<execution>
<goals>
<!--<goal>generateStubs</goal>-->
<goal>compile</goal>
<!--<goal>generateTestStubs</goal>-->
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Project structure
pom.xml
src/main/groovy
src/main/java
src/test/groovy
src/test/java
Features
- Using groovy 1.7.1. GDK because of dependency to groovy-all
- Supports Groovy 1.7 syntax (enums, etc.) because of providerSelection 1.7
- Supports Java 1.5 syntax (enums, generics, etc.) because of maven-compiler-plugin source 1.5
- Groovy classes may reference Java classes, but not vice versa
- If you need to reference groovy classes from java classes, enable generateStubs, but caution: The gmaven plugin has some bugs with generateStubs, e.g. it does not support interfaces with constants in it!
