There are several possible ways to configure Groovy Eclipse Plugin - see official http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven page.
Our recommendation is to use configuration similar to the following:
<sourceDirectory>src/main/groovy</sourceDirectory> <testSourceDirectory>src/test/groovy</testSourceDirectory>
instead of this use:
extensions=true for groovy-eclipse-compiler (Maven 3) or
build-helper-maven-plugin to define additional source roots (Maven 2)
<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>
<groupId>com.atlassian.samples</groupId>
<artifactId>groovy-eclipse-plugin-maven3-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Groovy Eclipse Plug-in Sample for Maven 3</name>
<!-- Dependencies for test execution and runtime -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<!-- Bind Groovy Eclipse Compiler -->
<compilerId>groovy-eclipse-compiler</compilerId>
<source>1.6</source>
<target>1.6</target>
</configuration>
<dependencies>
<!-- Define which Groovy version will be used for build (default is 2.0) -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>1.8.6-01</version>
</dependency>
<!-- Define dependency to Groovy Eclipse Compiler (as it's referred in compilerId) -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
</dependencies>
</plugin>
<!-- Define Groovy Eclipse Compiler again and set extensions=true. Thanks to this, plugin will -->
<!-- enhance default build life cycle with an extra phase which adds additional Groovy source folders -->
<!-- Thanks to this, Clover will be able to find your Groovy files. It works with Maven 3.x -->
<plugin>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
<extensions>true</extensions>
</plugin>
<!-- Configure Clover for Maven plug-in. Please note that it's not bound to any execution phase, -->
<!-- so you'll have to call Clover goals from command line. -->
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.3</version>
</plugin>
</plugins>
</build>
</project>
In the build log you'll find messages like:
[INFO] --- groovy-eclipse-compiler:2.7.0-01:add-groovy-build-paths (default-add-groovy-build-paths) @ groovy-eclipse-plugin-maven3-sample --- [INFO] Adding /src/main/groovy to the list of source folders [INFO] Adding /src/test/groovy to the list of test source folders
Build life cycle extension (used by groovy-eclipse-compiler) is not supported in Maven 2.x. Therefore, you can add source locations via build-helper-maven-plugin.
<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>
<groupId>com.atlassian.samples</groupId>
<artifactId>groovy-eclipse-plugin-maven2-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Groovy Eclipse Plug-in Sample for Maven 2</name>
<!-- Dependencies for test execution and runtime -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<!-- Bind Groovy Eclipse Compiler -->
<compilerId>groovy-eclipse-compiler</compilerId>
<source>1.6</source>
<target>1.6</target>
</configuration>
<dependencies>
<!-- Define which Groovy version will be used for build (default is 2.0) -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>1.8.6-01</version>
</dependency>
<!-- Define dependency to Groovy Eclipse Compiler (as it's referred in compilerId) -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
</dependencies>
</plugin>
<!-- Use Build Helper plugin which adds new source folders for Groovy, without modifying build cycle -->
<!-- (as groovy-eclipse-compiler extensions="true" does). Thanks to this, Clover will be able -->
<!-- to find your Groovy sources. Works for Maven 2.x and 3.x -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/groovy</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Configure Clover for Maven plug-in. Please note that it's not bound to any execution phase, -->
<!-- so you'll have to call Clover goals from command line. -->
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.3</version>
</plugin>
</plugins>
</build>
</project>
In the build log you'll find messages like:
[INFO] [build-helper:add-source {execution: add-source}]
[INFO] Source directory: c:\MyProject\src\main\groovy added.
...
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[INFO] [build-helper:add-test-source {execution: add-test-source}]
[INFO] Test Source directory: c:\MyProject\src\test\groovy added.
...
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
Run your build with Clover using a following command (Maven 2 & 3):
mvn clean clover2:setup install clover2:aggregate clover2:clover
Bug Warning for Clover 3.1.11 and older
Because of bug CLOV-1144 (fixed in 3.1.12) you have to keep your *.groovy files not in the location for Java code. If you put your Groovy sources into src/main/java or src/test/java (and this is unfortunately suggested solution on Groovy-Eclipse+compiler+plugin+for+Maven official page), you will end up with an error message like below:
[INFO] BUILD FAILURE ... [ERROR] Failed to execute goal com.atlassian.maven.plugins:maven-clover2-plugin:3.1.7:setup (default-cli)
...
Clover has failed to instrument the source files in the [C:\MyProject\target\clover\src-instrumented] directory at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) ... [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException *** ERROR: No source files specified USAGE: com.cenqua.clover.CloverInstr [OPTIONS] PARAMS [FILES...] ...
Checkout sources of the maven-clover2-plugin from Bitbucket:
hg clone https://bitbucket.org/atlassian/maven-clover2-plugin
Open the src/it directory. It contains a number of sample projects, including:
groovy-eclipse-plugin - shows an approach in which Groovy sources are stored in 'src/main/groovy' and 'src/test/groovy', while Java sources in 'src/main/java' and 'src/test/java'