gmaven-plugin works for groovy 1.7.5 but not for 2

2019-05-17 19:45发布

I have working maven 2 setup which compiles jUnit tests written in groovy. Both java and groovy tests are located at /src/test/java

See a snapshot of the pom.xml

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
        <id>testCompile</id>
        <goals>
            <goal>testCompile</goal>
        </goals>
        <configuration>
            <sources>
                <fileset>
                    <directory>${pom.basedir}/src/test/java</directory>
                    <includes>
                        <include>**/*.groovy</include>
                    </includes>
                </fileset>
            </sources>
        </configuration>
        </execution>
    </executions>
</plugin>

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy</artifactId>
    <version>1.7.5</version>
    <scope>test</scope>
</dependency>

When I upgrade to plugin version 1.5 and groovy 2.1.0, */.groovy files are ignored. Has anybody met up with this problem?

4条回答
SAY GOODBYE
2楼-- · 2019-05-17 20:21

First, each GMaven provider compiles against a particular version of Groovy, so there can be issues if Groovy breaks something with a point release. Second, GMaven is no longer maintained (that's why you don't see any providers for newer Groovy versions). I recommend switching to GMavenPlus or the Groovy-Eclipse compiler plugin for Maven.

查看更多
乱世女痞
3楼-- · 2019-05-17 20:23

Ok, this configuration works for maven 2.

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.4</version>
        <configuration>
            <providerSelection>2.0</providerSelection>
            <sourceEncoding>UTF-8</sourceEncoding>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>testCompile</goal>
                </goals>
                <configuration>
                    <sources>
                        <fileset>
                            <directory>${pom.basedir}/src/test/java</directory>
                            <includes>
                                <include>**/*.groovy</include>
                            </includes>
                        </fileset>
                    </sources>
                </configuration>
            </execution>
        </executions>
</plugin>

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy</artifactId>
    <version>2.0.0</version>
    <scope>test</scope>
</dependency>
查看更多
女痞
4楼-- · 2019-05-17 20:23

I experience the same problem, but downgrading to gmaven 1.4 solves the problem (using groovy-all 2.3.2)

查看更多
何必那么认真
5楼-- · 2019-05-17 20:24

I found this page https://confluence.atlassian.com/display/CLOVER/Compiling+Groovy+with+GMaven+plugin

Note that you must put your Groovy Classes and Tests under src/main/groovy and src/test/groovy respectively.

Following configuration based on that page seems to work:

        <!-- Groovy and Maven https://confluence.atlassian.com/display/CLOVER/Compiling+Groovy+with+GMaven+plugin -->
        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>${gmaven.version}</version>
            <configuration>
                <providerSelection>2.0</providerSelection>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.gmaven.runtime</groupId>
                    <artifactId>gmaven-runtime-2.0</artifactId>
                    <version>${gmaven.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>${groovy.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>generateStubs</goal>
                        <goal>compile</goal>
                        <goal>generateTestStubs</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

And in dependencies of course

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>${groovy.version}</version>
    </dependency>

And in properties

<properties>
    <gmaven.version>1.5</gmaven.version>
    <groovy.version>2.1.8</groovy.version>
</properties>
查看更多
登录 后发表回答