在我的 build.gradle 文件中,我有一行依赖项:
compile group: 'org.jboss.seam.validation', name: 'seam-validation-api', version:'3.1.0.Final'
当我尝试运行该项目时,例如“测试”任务,我收到错误:
> Could not resolve org.jboss.seam.validation:seam-validation-api:3.1.0.Final.
Required by:
com.smspl.mc5:mc5-web-ui:1.0.0-SNAPSHOT
com.smspl.mc5:mc5-web-ui:1.0.0-SNAPSHOT > com.smspl.mc5:mc5-common-rest:1.0.0-SNAPSHOT
> Could not parse POM /Users/amorfis/.m2/repository/org/jboss/seam/validation/seam-validation-api/3.1.0.Final/seam-validation-api-3.1.0.Final.pom
> Unable to resolve version for dependency 'javax.enterprise:cdi-api:jar'
> Could not parse POM https://nexus.softwaremill.com/content/groups/smlcommon-repos/org/jboss/seam/validation/seam-validation-api/3.1.0.Final/seam-validation-api-3.1.0.Final.pom
> Unable to resolve version for dependency 'javax.enterprise:cdi-api:jar'
我知道问题是在 seam-validation-api pom 中未指定“javax.enterprise:cdi-api:jar”的版本。它是在它的父级中指定的,而 gradle 可能在解决它时遇到一些问题。 seam-validation-api pom 的父部分如下所示:
<parent>
<groupId>org.jboss.seam.validation</groupId>
<artifactId>seam-validation-parent</artifactId>
<version>3.1.0.Final</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
我的直觉告诉我问题是部分的。我还尝试通过向 build.gradle“依赖项”添加新行来显式添加此父依赖项,但没有任何运气。
有人知道这个问题的解决办法吗?
更新:在父pom中:
<groupId>org.jboss.seam.validation</groupId>
<artifactId>seam-validation-parent</artifactId>
<packaging>pom</packaging>
<version>3.1.0.Final</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-bom</artifactId>
<version>${seam.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
最佳答案
这是对该问题的一些研究(仅是研究,不是解决方案):
seam-validation-api-3.1.0.Final.pom有父 seam-validation-parent-3.1.0.Final.pom
seam-validation-parent-3.1.0.Final.pom 具有父项 seam-parent-19.pom
文件 seam-parent-4.pom包含 cdi-api 的版本定义,但 seam-parent-19.pom 不包含。
文件 seam-validation-parent-3.0.0.Final.pom确实包含 cdi-api 的 dependencyManagement,但较新版本 seam-validation-parent-3.1.0.Final.pom没有。
我还研究了 GradlePomModuleDescriptorBuilder 的代码(抛出上述“无法解析...”异常的类)。看起来该类在父 pom 链上查找 DependencyManagement 部分,但它不尊重解析策略(或 gradle 脚本中的任何其他定义)。因此目前无法增强/覆盖 POM 的 dependencyManagement。
我的建议:联系seam框架的开发人员并要求他们修复依赖关系。
关于Gradle 无法解决依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935891/