Build Groovy++ with Maven
Friday, February 26. 2010
Please see my update Official-Maven-support-for-Groovypp.
If you are already a fan of Groovy you probably will also be a fan of the rising star Groovy++. Even people that dislike the dynamic magic of Groovy must agree, that this is cool stuff, mixing the power of Groovy with the safety and performance of classical Java. Since Groovy++ is still brand new it lacks of any Maven support today. In the following I will show how you can tweak the GMaven plugin for using the Groovy++ extensions.
Please be aware that this is just a very quick work to get it running and might not be stable. For example I did not verify all the necessary dependencies. So further work has to be done.
Prepare your System
Start downloading Groovy++ from http://code.google.com/p/groovypptest/ and extract it.
Get a working copy of the gmaven plugin by using Subversion checkout:
svn co https://svn.codehaus.org/groovy/gmaven/tags/gmaven-1.0
Create a copy of the <gmaven>/gmaven-runtime/gmaven-runtime-1.6 to <gmaven>gmaven-runtime/gmaven-runtime-1.8.
svn cp gmaven-runtime-1.6 gmaven-runtime-1.8
Go the gmaven-runtime/gmaven-runtime-1.8 directory and edit the pom.xml file and rename all occurences of version 1.6 to 1.8:
- <name>GMaven Runtime :: 1.6</name> - <artifactId>gmaven-runtime-1.6</artifactId> + <name>GMaven Runtime :: 1.8</name> + <artifactId>gmaven-runtime-1.8</artifactId> ... <description> - Support for Groovy 1.6.x. + Support for Groovy 1.8.x. </description> ... <dependency> <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - <version>1.6.0</version> + <artifactId>groovy</artifactId> + <version>1.8.0-beta-1-SNAPSHOT</version> <exclusions> ...
Finally add the new module to the parent POM in <GMAVEN>/pom.xml:
<modules> ... + <module>gmaven-runtime-1.8</module> ... </modules>
and import the project into your favorite IDE. For good Groovy support I suggest to use Idea.
Open the gmaven-runtime-1.8 project and use the refactoring feature to rename the org/codehaus/groovy/maven/runtime/v1_6 package to org/codehaus/groovy/maven/runtime/v1_8.
WARNING: Make sure not to rename the package of the gmaven-runtime-1.6 packages!
Now it is time to upload the needed artifacts into the local Maven repository.
mvn install:install-file \ -DgroupId=org.codehaus.groovy \ -DartifactId=groovy \ -Dversion=1.8.0-beta-1-SNAPSHOT \ -Dpackaging=jar \ -Dfile=<GROOVYPP>/lib/groovy-1.8.0-beta-1-SNAPSHOT.jar mvn install:install-file \ -DgroupId=org.codehaus.groovy \ -DartifactId=groovypp \ -Dversion=1.8.0-beta-1-SNAPSHOT \ -Dpackaging=jar \ -Dfile=<GROOVYPP>/lib/groovypp.jar
In order to make sure that the transitive dependencies are handled correctly edit the POM files and add the dependencies to them:
Edit <M2_REPO>/repository/org/codehaus/groovy/groovy/1.8.0-beta-1-SNAPSHOT/groovy-1.8.0-beta-1-SNAPSHOT.pom and insert the following content:
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy</artifactId> <version>1.8.0-beta-1-SNAPSHOT</version> <description>POM was created from install:install-file</description> <dependencies> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.2</version> </dependency> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.7.1</version> </dependency> </dependencies> </project>
Similar with <M2_REPO>/repository/org/codehaus/groovy/groovypp/1.8.0-beta-1-SNAPSHOT/groovypp-1.8.0-beta-1-SNAPSHOT.pom
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.codehaus.groovy</groupId> <artifactId>groovypp</artifactId> <version>1.8.0-beta-1-SNAPSHOT</version> <description>POM was created from install:install-file</description> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy</artifactId> <version>1.8.0-beta-1-SNAPSHOT</version> <exclusions> <exclusion> <groupId>junit</groupId> <artifactId>junit</artifactId> </exclusion> <exclusion> <groupId>jline</groupId> <artifactId>jline</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project>
Extend the GMaven plugin
Before we now can start a compile we need to do a few minor changes:
Open <GMAVEN>/gmaven-runtime-1.6/src/main/java/org/codehaus/groovy/maven/runtime/v1_8/ProviderImpl.java and replace the following version information:
- package org.codehaus.groovy.maven.runtime.v1_6; + package org.codehaus.groovy.maven.runtime.v1_8; ... - public static final String KEY = "1.6"; + public static final String KEY = "1.8"; ... - return new Version(1, 6, 0); + return new Version(1, 8, 0);
And again <GMAVEN>/gmaven-runtime/gmaven-runtime-1.8/src/main/java/org/codehaus/groovy/maven/runtime/v1_8/stubgen/ParserFactoryImpl.java:
- import groovyjarjarantlr.RecognitionException; - import groovyjarjarantlr.collections.AST; + import antlr.collections.AST; + import antlr.RecognitionException;
Now we are complete for rebuilding the gmaven plugin.
WARNING: In order to not overwrite the original plugin, you need to replace all artifact versions of the gmaven plugin with a new version, like 1.1-SNAPSHOT.
mvn clean install
Let's Start
It's time to create a project for testing our new plugin. Create a new Groovy project goovypptest and create a pom.xml file:
<?xml version="1.0" encoding="UTF-8"?> <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>groovypptest</groupId> <artifactId>groovypptest</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovypp</artifactId> <version>1.8.0-beta-1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.groovy.maven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.0</version> <configuration> <providerSelection>1.8</providerSelection> <debug>false</debug> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovypp</artifactId> <version>1.8.0-beta-1-SNAPSHOT</version> </dependency> </dependencies> <executions> <execution> <goals> <goal>generateStubs</goal> <goal>compile</goal> <goal>generateTestStubs</goal> <goal>testCompile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Please note that we are refering to the groovypp artifact in the dependency section as well as in the plugin section and we are referring to the new gmaven-runtime-1.8 by using the providerSelection option.
We are close to be done, now we add a sample program to <GROOVYPPTEST>/src/main/groovy/groovypptest/GroovySample.groovy
package groovypp
@Typed // This is way we are doing this here!
class GroovyppSample {
public void run() {
println "Hallo"
}
public static void main(String[] argv ) {
GroovyppSample sample = new GroovyppSample();
sample.run()
}
}
Finally build your Groovy++ project and join us in the new Groovy++ world.
Trackbacks
Trackback specific URI for this entry



I'm glad to be able to depricate my own post Groovy++-with-Maven a couple of weeks ago. The Groovy++ team has already taken action and provides the groovvypp libraries in a commonly accessible repository. They also provide a preliminary version of the gma
Tracked: Apr 02, 14:36