How to resolve parent pom dependency issue: Failed to read artifact descriptor; Could not find artifact?
Asked Answered
T

2

8

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.

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   

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?

Tintinnabulation answered 4/9, 2018 at 20:1 Comment(0)
P
17

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?

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>

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.

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.

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>

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>

About your comment :

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

it is expected as the 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

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>
Parliament answered 4/9, 2018 at 20:35 Comment(11)
For the parent standalone you can't use this and it will not work nor intended for this. Only inside a multimodule build you could use this in a parent under root pom...but the root if it has a parent must give a literal version number.... (Details see issues.apache.org/jira/browse/MNG-6438 )Chauvin
@Chauvin Are you sure ? Actually the parent is not a standalone project but is a multi module project. I already use this one with a similar setup and this worked if my memories are correct..Parliament
@Chauvin First : thank you to having implemented it :) I just tested it with the git project of the OP and by specifying a local path in the distribution management it works : the dependencies are correctly specified in the pom of the deployed artifacts. In the actual project, the pom.xml of the parent/multi module project doesn't have any parent. I think that the case you referenced is different.Parliament
@Chauvin Just personal. I like very much Maven and wondered if I could contribute. As far as you know, would the community need some support or the issues are already fast enough handled ?Parliament
Apache Maven is an open source project and it is always appreciated to have contributions / help in any kind of ways. Please go to maven.apache.org/guides/development/guide-helping.html and read... also you can ask on the dev list how/where you can help...I think there are much opportunities...to help.. It would be great if you like to help...Also you can write an email to me personally if you prefer that....Chauvin
Let us continue this discussion in chat.Parliament
@Parliament Thanks for the suggestion; I'm in the process of trying it out, but am stuck in deployment to maven central of the original updated dependency; 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, if that is related. Current status: github.com/ncrncornell/ced2ar-rdb/tree/…Tintinnabulation
@Tintinnabulation Your configuration looks fine. But the flatten plugin strips some metadata. So you should specify that you want to keep them. I updated my answer.Parliament
@Parliament thanks for pointing that out; it now uploads and will try to use it later today. I found that <flattenMode>ossrh</flattenMode> also works as an alternative to listing individual pomElements. One oddity I did find, was that I still had to manually add <name>CED2AR 3</name> to each of the child poms.Tintinnabulation
@Tintinnabulation you are welcome. Great that it's progressing :) Maybe you could use oss mode. That seems which one that keeps the maximum of optional elements. you could give it a go.Parliament
For my parent BOM (bill of materials) the option <flattenMode>bom</flattenMode> was the right choice.Bindery
R
0

This works well for child modules that are directly under the parent module, but I can't get mvn install to work for child modules that are more than 1 level deep when one of the child modules depends on another child module. For example, consider this hierarchy:

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

With the configuration described in the maven docs, I can run mvn install successfully from all directories except child-2. In child-2, I get this error:

[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]
Reiser answered 27/10, 2022 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.