如何解决父pom依赖问题:无法读取工件描述符;找不到神器?



我最近向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 的 reactor 项目,则无法解析子项目的父版本中定义的${ced2ar.version}属性。 这就是为什么你的构建在开发中工作(使用反应堆(,但没有它就无法工作。

若要解决您的问题,您可以将revision标准属性与flatten-maven-plugin一起使用,该属性将帮助您在父级和子级之间设置唯一版本。

您的反应器绒球可能看起来像:

<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>

和rdbpom.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 的简化版本,具有 焦点仅包含用于使用它的重要信息。因此,仅维护所需的信息 开发人员和构建项目工件将被剥离。开始 从这里我们指定如何从 原始聚甲醛及其项目

但是您可以通过在插件的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>

这适用于直接位于父模块下的子模块,但是当其中一个子模块依赖于另一个子模块时,我无法mvn install适用于深度超过 1 级的子模块。例如,请考虑以下层次结构:

└── root (pom type)
└── child (pom type) 
├── child-1 (jar type)
└── child-2 (jar type; depends on child-1)

使用 maven 文档中描述的配置,我可以从除child-2之外的所有目录中成功运行mvn install。在child-2,我收到此错误:

[ERROR] Failed to execute goal on project child-2: Could not resolve dependencies for project com.mygroup:child-2:maven-archetype:local: Failed to collect dependencies at com.mygroup:child-1:jar:local: Failed to read artifact descriptor for com.mygroup:child-1:jar:local: com.mygroup:root:pom:${revision} was not found in https://maven-central.storage-download.googleapis.com/maven2/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

相关内容

最新更新