6

I want to auto compile and run test when I use mvn test or mvn install

I used to use gmaven-plugin and it works will.

But when I use the groovy-maven-plugin,the new version of gmaven, it doesn't work!

So how to config?

Here is my pom.xml:

<!-- gmaven-plugin -->
<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <providerSelection>2.0</providerSelection>
        <source/>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generateStubs</goal>
                <goal>compile</goal>
                <goal>generateTestStubs</goal>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.gmaven.runtime</groupId>
            <artifactId>gmaven-runtime-2.0</artifactId>
            <version>1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>${groovy.version}</version>
        </dependency>
    </dependencies>
</plugin>

<!-- groovy-maven-plugin -->
<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>groovy-maven-plugin</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>${groovy.version}</version>
    </dependency>
  </dependencies>
</plugin>
Dozer
  • 5,025
  • 11
  • 36
  • 52
  • What happens when it is not working? do you get an error message? – Dror Bereznitsky Feb 26 '14 at 15:52
  • I believe the original groovy maven plugin is no longer under development, generally the Eclipse Groovy compiler plugin is favored for maven: http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven – cjstehno Feb 26 '14 at 18:32
  • @drorb there is no errors,but when I run `mvn test`,the new plugin will not run the groovy test. But the version `1.5` will. – Dozer Feb 27 '14 at 03:06

2 Answers2

5

Aside from the Groovy Eclipse Compiler, there's also a new GMavenPlus plugin that can support joint compilation.

In regards to testing, here's a POM sample of my project which has the GMavenPlus plugin working with Spock.

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>            
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generateStubs</goal>
                            <goal>compile</goal>
                            <goal>testGenerateStubs</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>5</threadCount>
                    <includes>
                        <include>**/*Test.*</include>
                        <include>**/*Spec.*</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>0.7-groovy-2.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit-dep</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
bdkosher
  • 5,753
  • 2
  • 33
  • 40
0

According to the GMaven 2.x documentation it no longer supports any integration for compilation of Groovy sources. As an alternative it is suggested to use the Groovy Eclipse Compiler.
The groovy-maven-plugin goals allows to open a groovy console or execute a groovy script, but no longer have the compilation goals.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57