如何解决父pom依赖性问题:无法读取工件描述符;找不到文物? [英] How to resolve parent pom dependency issue: Failed to read artifact descriptor; Could not find artifact?

查看:178
本文介绍了如何解决父pom依赖性问题:无法读取工件描述符;找不到文物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I recently published three artifacts to Maven Central: https://search.maven.org/search?q=ced2ar3-rdb

这三个是同一项目的一部分,并同时发布.

The three are part of the same project and are published concurrently.

我现在正在尝试使用ced2ar-rdb和ced2ar-rdb-tests作为依赖项来构建新项目,但不在我的代码中引用父pom文件的位置(ced2ar3-rdb-parent;我没有确实想使用它,却不认为我需要它).但是,当我尝试构建使用ced2ar-rdb作为依赖项的项目时,出现此错误:

I'm now trying to build a new project using ced2ar-rdb and ced2ar-rdb-tests as dependencies, but not where in my code do I reference the parent pom file (ced2ar3-rdb-parent; I don't actually want to use it and didn't think I needed it). However, when I try to build my project that uses ced2ar-rdb as a dependency, I get this error:

[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   

即使${ced2ar.version}在文件中更下方的<properties>中正确定义了,这个问题是否与我在父pom中具有<version>${ced2ar.version}</version>的事实有关?

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

推荐答案

这个问题与我有以下事实有关吗? $ {ced2ar.version}在父pom中,即使 $ {ced2ar.version}似乎在进一步的定义中正确 在文件中?

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 ./p>

No, the problem comes from the way which you declared the child modules.
Here is an extract of the rdb module 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.这就是为什么您的构建可以在开发中(使用Reactor)工作但没有它就无法工作的原因.

The ${ced2ar.version} property defined in the parent version of the child project cannot be resolved without building the reactor project that first builds the parent pom that defines this property. That's why your build works in development (with the reactor) but doesn't work without it.

要解决您的问题您可以将revision标准属性flatten-maven-plugin,它将帮助您在父级和子级之间设置唯一的版本.

To solve your issue you could use the revision standard property with the flatten-maven-plugin that will help you to set a unique version between the parent and the child.

您的反应堆pom可能如下所示:

Your reactor pom could look like :

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

And the rdb pom.xml for example like that :

<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,我看不到这些字段

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

由于扁平化插件会剥离原始POM的某些元数据,因此可以预期:

it is expected as the flattened plugin strips some metadata of the original POM :

扁平化的POM是原始POM的简化版本,带有 专注于仅包含重要信息以供使用. 因此,仅在以下情况下才需要维护的信息 开发人员和用于构建项目工件的工作被剥夺了.开始 从这里我们指定如何从 原始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参数中添加不想删除的元素来覆盖此默认设置.
例如:

But you can override this default by adding the elements that you don't want to strip in the pomElements parameter of the plugin.
For example :

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

这篇关于如何解决父pom依赖性问题:无法读取工件描述符;找不到文物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆