Tuesday, 28 June 2011

gmaven with groovy++

It took me a while to scratch around and find all the right bits. If you want to use groovy++ and the latest gmaven plugin then here's a sample pom that does the trick.

Groovy++ can be replaced with org.codehaus.groovy:groovy-all:1.8.0. Groovy++ is useful in that it does compile time type checking. This can save a huge amount of wasted in trying to figure out runtime errors.

The latest gmaven requires the use of annomojo annotations.

Ihave to thanks Evgeny Goldin for posting some working examples on his blog. His github collection of gmaven plugins is very handy both as a reference and for getting various tricky tasks accomplished.

 <?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>org.thump</groupId>  
      <artifactId>neil-maven-plugins</artifactId>  
      <version>1.0-SNAPSHOT</version>  
      <packaging>maven-plugin</packaging>  
      <dependencies>  
           <dependency>  
                <groupId>org.mbte.groovypp</groupId>  
                <artifactId>groovypp-all</artifactId>  
                <version>0.4.217</version>  
           </dependency>  
           <dependency>  
                <groupId>junit</groupId>  
                <artifactId>junit</artifactId>  
                <version>4.7</version>  
                <scope>test</scope>  
           </dependency>  
           <dependency>  
                <groupId>org.codehaus.gmaven</groupId>  
                <artifactId>gmaven-mojo</artifactId>  
                <version>1.3</version>  
           </dependency>  
           <dependency>  
                <groupId>org.jfrog.maven.annomojo</groupId>  
                <artifactId>maven-plugin-anno</artifactId>  
                <version>1.4.0</version>  
           </dependency>  
      </dependencies>  
      <build>  
           <plugins>  
                <plugin>  
                     <groupId>org.apache.maven.plugins</groupId>  
                     <artifactId>maven-plugin-plugin</artifactId>  
                     <version>2.7</version>  
                     <dependencies>  
                          <dependency>  
                               <groupId>org.apache.maven.plugin-tools</groupId>  
                               <artifactId>maven-plugin-tools-api</artifactId>  
                               <version>2.7</version>  
                          </dependency>  
                          <dependency>  
                               <groupId>org.jfrog.maven.annomojo</groupId>  
                               <artifactId>maven-plugin-tools-anno</artifactId>  
                               <version>1.4.0</version>  
                               <scope>runtime</scope>  
                          </dependency>  
                     </dependencies>  
                </plugin>  
                <plugin>  
                     <groupId>org.codehaus.gmaven</groupId>  
                     <artifactId>gmaven-plugin</artifactId>  
                     <version>1.3</version>  
                     <configuration>  
                          <providerSelection>1.7</providerSelection>  
                     </configuration>  
                     <executions>  
                          <execution>  
                               <id>generate-stubs</id>  
                               <phase>generate-sources</phase>  
                               <goals>  
                                    <goal>generateStubs</goal>  
                               </goals>  
                          </execution>  
                          <execution>  
                               <id>compile-groovy</id>  
                               <phase>process-sources</phase>  
                               <goals>  
                                    <goal>compile</goal>  
                               </goals>  
                          </execution>  
                     </executions>  
                     <dependencies>  
                          <dependency>  
                               <groupId>org.mbte.groovypp</groupId>  
                               <artifactId>groovypp-all</artifactId>  
                               <version>0.4.217</version>  
                          </dependency>  
                          <dependency>  
                               <groupId>org.codehaus.gmaven.runtime</groupId>  
                               <artifactId>gmaven-runtime-1.7</artifactId>  
                               <version>1.3</version>  
                               <exclusions>  
                                    <exclusion>  
                                         <groupId>org.codehaus.groovy</groupId>  
                                         <artifactId>groovy-all</artifactId>  
                                    </exclusion>  
                               </exclusions>  
                          </dependency>  
                     </dependencies>  
                </plugin>  
           </plugins>  
      </build>  
 </project>  



A simple groovy mojo:

 import org.apache.maven.project.MavenProject;  
 import org.codehaus.gmaven.mojo.GroovyMojo  
 import org.jfrog.maven.annomojo.annotations.*  
 @Typed  
 @MojoGoal("sayhello")  
 @MojoPhase("package")  
 public class TestMojo extends GroovyMojo {  
      @MojoParameter ( expression = '${project}', required=true)  
      public MavenProject mavenProject  
      @MojoParameter  
      def public String message  
   void execute() {  
     log.info("Saying Hello")  
     println "${message}"  
   }  
 }  

No comments:

Powered by Blogger.