GMaven构建失败,“遇到API不兼容”

时间:2012-10-28 21:21:56

标签: java maven groovy gmaven

尝试使用Maven Gmaven插件编译项目时,发生以下错误:

  

[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:compile (default) on project concorde-web: Execution default of goal org.codehaus.gmaven:gmaven-plugin:1.4:compile failed: An API incompatibility was encountered while executing org.codehaus.gmaven:gmaven-plugin:1.4:compile: java.lang.NoSuchMethodError: org.codehaus.groovy.ast.ModuleNode.getStarImports()Ljava/util/List;

谷歌搜索表明这是因为多个groovy版本在我的依赖链中结束。但是,在检查完整的依赖关系树之后,我发现整个树中只有一个依赖关系。

以下是我的pom.xml的摘录:

    <!-- Groovy dependencies -->
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>1.8.5</version>
    </dependency>
    <!-- ... snip ... -->

        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generateStubs</goal>
                        <goal>compile</goal>
                        <goal>generateTestStubs</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

3 个答案:

答案 0 :(得分:13)

这是由GMaven插件定义中缺少providerSelection元素引起的。

正确的GMaven定义如下:

        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.4</version>
            <configuration>
                <providerSelection>1.8</providerSelection>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generateStubs</goal>
                        <goal>compile</goal>
                        <goal>generateTestStubs</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

答案 1 :(得分:0)

通过对Marty解决方案的一些小改动,我能够让它发挥作用:

<plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.5</version>

        <executions>
            <execution>
                <configuration>
                    <providerSelection>2.0</providerSelection>
                </configuration>
                <goals>
                    <goal>generateStubs</goal>
                    <goal>compile</goal>
                    <goal>generateTestStubs</goal>
                    <goal>testCompile</goal>
                </goals>
            </execution>
        </executions>
</plugin>

答案 2 :(得分:0)

我在项目中遇到的错误,但经过长时间的诊断后发现与以下依赖关系相关的jar已损坏。

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>1.8.5</version>
</dependency>