![](/img/trans.png)
[英]Maven “could not resolve dependencies” and “failed to read artifact descriptor” error
[英]How to resolve parent pom dependency issue: Failed to read artifact descriptor; Could not find artifact?
我最近向Maven Central發布了三個工件: https : //search.maven.org/search? q = ced2ar3- rdb
這三個是同一項目的一部分,並且同時發布。
我現在正在嘗試使用ced2ar-rdb和ced2ar-rdb-tests作為依賴項來構建新項目,但不是在我的代碼中引用父pom文件的位置(ced2ar3-rdb-parent;我實際上不想使用它,並且認為我不需要它)。 但是,當我嘗試構建使用ced2ar-rdb作為依賴項的項目時,出現以下錯誤:
[ERROR] Failed to execute goal on project ced2ar3-services-core: Could not resolve dependencies for project edu.cornell.
ncrn.ced2ar:ced2ar3-services-core:jar:0.0.0: Failed to collect dependencies at edu.cornell.ncrn.ced2ar:ced2ar3-rdb:jar:0
.0.1: Failed to read artifact descriptor for edu.cornell.ncrn.ced2ar:ced2ar3-rdb:jar:0.0.1: Could not find artifact edu.
cornell.ncrn.ced2ar:ced2ar3-rdb-parent:pom:${ced2ar.version} in central (https://repo.maven.apache.org/maven2) -> [Help
問題與我在父pom中具有<version>${ced2ar.version}</version>
的事實有關,即使${ced2ar.version}
在文件的更下方的<properties>
中正確定義了也是如此?
即使$ {ced2ar.version}在文件的更下方定義正確,該問題是否與我在父pom中具有$ {ced2ar.version}的事實有關?
不,問題出在聲明子模塊的方式上。
這是rdb模塊pom的摘錄。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ced2ar3-rdb-parent</artifactId>
<groupId>edu.cornell.ncrn.ced2ar</groupId>
<version>${ced2ar.version}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ced2ar3-rdb</artifactId>
</project>
如果不構建先構建定義該屬性的父pom的反應堆項目,則無法解析子項目的父版本中定義的${ced2ar.version}
屬性。 這就是為什么您的構建可以在開發中(使用Reactor)工作但沒有它就無法工作的原因。
要解決您的問題, 您可以將revision
標准屬性與flatten-maven-plugin
,這將幫助您在父級和子級之間設置唯一的版本。
您的反應堆pom可能看起來像:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>${revision}</version>
...
<properties>
<revision>1.0.0</revision>
</properties>
<modules>
<module>rdb</module>
<module>rdb-tests</module>
..
</modules>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
和rdb pom.xml這樣的例子:
<project>
<parent>
<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>${revision}</version>
</parent>
<artifactId>rdb</artifactId>
...
</project>
關於您的評論:
我收到無效的POM錯誤,內容為:“缺少項目名稱,項目描述缺失,項目URL缺失,SCM URL缺失,開發人員信息缺失”。 確實,在檢查了生成的.flattened-pom.xml之后,我沒有看到這些字段
由於扁平化插件會剝離原始POM的一些元數據,因此可以預期:
扁平化的POM是原始POM的簡化版本,重點是僅包含使用它的重要信息。 因此,僅剝奪了開發人員維護和構建項目工件所需的信息 。 從這里開始,我們指定如何從原始POM及其項目創建展平的POM。
但是您可以通過在插件的pomElements
參數中添加不想刪除的元素來覆蓋此默認設置。
例如 :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<pomElements>
<name/>
<description/>
<developers/>
<contributors/>
<url/>
<scm/>
</pomElements>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.