gmaven-plugin works for groovy 1.7.5 but not for 2.1.0

主宰稳场 提交于 2019-12-07 15:55:44

问题


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?


回答1:


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>



回答2:


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>



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/14643943/gmaven-plugin-works-for-groovy-1-7-5-but-not-for-2-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!