gpt4 book ai didi

maven - 如何解决父 pom 依赖问题 : Failed to read artifact descriptor; Could not find artifact?

转载 作者:行者123 更新时间:2023-12-03 18:35:16 27 4
gpt4 key购买 nike

我最近向 Maven Central 发布了三个 Artifact :https://search.maven.org/search?q=ced2ar3-rdb

这三个是 same project 的一部分并同时发布。

我现在正在尝试使用 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

问题是否与我拥有 <version>${ced2ar.version}</version> 的事实有关?在父 pom 中,即使 ${ced2ar.version}出现在 <properties> 中的正确定义在文件中进一步下降?

最佳答案

Is the issue related to the fact that I have ${ced2ar.version} in the parent pom, even though ${ced2ar.version} appears correctly defined in further down in the file?



不,问题来自您声明子模块的方式。
这是 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>
${ced2ar.version}如果不构建首先构建定义此属性的父 pom 的 react 器项目,则无法解析子项目的父版本中定义的属性。这就是为什么您的构建在开发中工作(使用 react 器)但没有它就无法工作的原因。

解决您的问题 you could use the revision standard propertyflatten-maven-plugin这将帮助您在 parent 和 child 之间设置一个独特的版本。

您的 react 堆 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>

关于您的评论:

I get an invalid POM error with: "Project name missing, Project description missing, Project URL missing, SCM URL missing, Developer information missing". Indeed, after inspecting the generated .flattened-pom.xml, I do not see these fields



预计为 flattened plugin strips some metadata of the original POM :

The flattened POM is a reduced version of the original POM with the focus to contain only the important information for consuming it. Therefore information that is only required for maintenance by developers and to build the project artifact(s) are stripped. Starting from here we specify how the flattened POM is created from the original POM and its project



但是你可以通过在 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>

关于maven - 如何解决父 pom 依赖问题 : Failed to read artifact descriptor; Could not find artifact?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52173260/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com