maven - 使用 groovy-eclipse-plugin 和 @Grab 时出错

标签 maven groovy grape

运行 mvn clean compile 时出现以下错误在新系统上。它在我的本地(windows)环境中运行良好。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project visa-threatintel: Compilation failure: Compilation failure:
[ERROR] /path/to/Class.groovy:[2,2] 1. ERROR in /path/to/Class.groovy (at line 2)
[ERROR] @Grab(group="javax.mail", module="mail", version="1.5.0-b01", type="jar"),
[ERROR] ^^^
[ERROR] Groovy:Ambiguous method overloading for method org.apache.ivy.core.settings.IvySettings#load.

本地和新系统都使用 Maven 3.2.5,POM 相同。相关摘录如下:
<groovy.version>2.2.1</groovy.version>
<ivy.version>2.4.0</ivy.version>


 <build>
    <plugins>
            <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <extensions>true</extensions>
                    <configuration>
                            <!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
                            <source>1.6</source>
                            <target>1.6</target>
                            <compilerId>groovy-eclipse-compiler</compilerId>
                    </configuration>
                    <dependencies>
                            <dependency>
                                    <groupId>org.codehaus.groovy</groupId>
                                    <artifactId>groovy-eclipse-compiler</artifactId>
                                    <version>2.9.0-01</version>
                            </dependency>
                            <!-- 2.2.1 version isn't available as a release, so it needs to be acquired
                                    from the codehaus nexus repository -->
                            <dependency>
                                    <groupId>org.codehaus.groovy</groupId>
                                    <artifactId>groovy-eclipse-batch</artifactId>
                                    <version>${groovy.version}-01-SNAPSHOT</version>
                            </dependency>
                            <!-- to allow @Grab annotations -->
                            <dependency>
                                    <groupId>org.apache.ivy</groupId>
                                    <artifactId>ivy</artifactId>
                                    <version>${ivy.version}</version>
                            </dependency>
                    </dependencies>
            </plugin>
            <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <executions>
                            <execution>
                                    <id>add-source</id>
                                    <phase>generate-sources</phase>
                                    <goals>
                                            <goal>add-source</goal>
                                    </goals>
                                    <configuration>
                                            <sources>
                                                    <source>src/main/groovy</source>
                                            </sources>
                                    </configuration>
                            </execution>

我尝试将 groovy 版本更改为 2.4.3,但遇到了同样的错误。有没有人见过这样的事情?

最佳答案

刚刚遇到类似的问题,我发现我有两个问题:

下载失败的Maven deps

Maven 依赖项 (maven-assembly-plugin) 下载失败。

删除 .lastUpdated本地 m2 存储库中的文件:

#> find ~/.m2/repository -name *.lastUpdated
~/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom.lastUpdated

#> find ~/.m2/repository -name *.lastUpdated -delete

Grape 配置.xml 和存储库 ssl 证书

还有您的 ~/.groovy/grapeConfig.xml需要配置文件以告诉 groovy 从何处提取依赖项 - 在我的情况下,它来自企业 nexus 存储库,这也意味着我必须在 JRE cacerts 文件中安装 https 证书。

如何测试

测试您是否正确设置所有内容的一个建议是调用 grape install在测试依赖项上,这将使您更清楚地了解什么是错误的( Grape 作为 groovy 二进制文件的一部分分发,因此将其包含在您的路径中,或完全限定其路径):
grape install javax.mail mail 1.5.0-b01

关于maven - 使用 groovy-eclipse-plugin 和 @Grab 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31172018/

相关文章:

ruby-on-rails - 为什么在Rails中安装路由会因 “uninitialized constant API”而失败?

docker - 使用Dockerfile for Java(Maven),NPM中的Azure Artifact 进行身份验证

java - "java could not find the main class"和 "could not read maven project"

Eclipse + maven 即使存在 POM 也无法打开

java - 从 map 中消除负数并与其他正数求和的算法

grails - Groovy/Grails 迭代列表并使用 NumberFormat(美国风格)格式化数字

Groovy 列表转换

ruby-on-rails - 继承在 Grape 中不起作用

ruby-on-rails - 如何用 Grape 返回空响应?

java - Fillo 依赖项不适用于 Maven 项目