MavenError: Failed to execute goal on project: Could not resolve dependencies In Maven Multimodule project

170,148

Solution 1

In case anybody comes back to this, I think the problem here was failing to install the parent pom first, which all these submodules depend on, so the Maven Reactor can't collect the necessary dependencies to build the submodule.

So from the root directory (here D:\luna_workspace\empire_club\empirecl) it probably just needs a:

mvn clean install

(Aside: <relativePath>../pom.xml</relativePath> is not really necessary as it's the default value).

Solution 2

In my case I forgot it was packaging conflict jar vs pom. I forgot to write

<packaging>pom</packaging>

In every child pom.xml file

Solution 3

My solution was to insert <packaging>pom</packaging> between artifactId and version

<groupId>com.onlinechat</groupId>
<artifactId>chat-online</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
    <module>server</module>
    <module>client</module>
    <module>network</module>
</modules>
Share:
170,148
Harmeet Singh Taara
Author by

Harmeet Singh Taara

Harmeet starts his career from Java EE development and building applications using Java frameworks. He is the die-hard fan of technology and exploring new approach, frameworks, methodology and more. With some industrial experience, he gains some knowledge about Scala and reactive applications and loves Lightbend technology stack. That's why he joins Knoldus. In knoldus start building application using Java 8 and Scala and other Lightbend technologies like Akka, Play, Lagom and more.

Updated on August 01, 2021

Comments

  • Harmeet Singh Taara
    Harmeet Singh Taara almost 3 years

    I am trying to create a maven multi-module project. the project is created successfully but when I am trying to use one module as a dependency of another module, it throws an exception. When I create a module using eclipse, I was selecting packaging as a jar, but when the module is created, the packaging tag was not mention in child pom.xml and I manually insert the packaging tag as a jar. following is my parent pom.xml:

    <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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.netsol</groupId>
    <artifactId>empirecl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    -------------------------
    <modules>
        <module>empirecl-web</module>
        <module>empirecl-dao</module>
        <module>empirecl-service</module>
        <module>empirecl-api</module>
    </modules>
    

    Dao Child Module:

    <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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.netsol</groupId>
        <artifactId>empirecl</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>empirecl-dao</artifactId>
    <packaging>jar</packaging>
    <name>empirecl-dao</name>
    ------------------------
    

    Service Child Module:

    <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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.netsol</groupId>
        <artifactId>empirecl</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>empirecl-service</artifactId>
    <packaging>jar</packaging>
    <name>empirecl-service</name>
    
    <dependencies>
        <dependency>
            <groupId>com.netsol</groupId>
            <artifactId>empirecl-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
    ------------------------------------------
    

    The Dao module maven clean and install successfully, but when i trying to use service module, it will generate an following exception:

    [ERROR] Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Could not find artifact com.netsol:empirecl:pom:0.0.1-SNAPSHOT -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT
    

    I am trying the find to solution from web, but still the solution is not found. In eclipse when i open the Dependency Hierarchy of service module, it shown the DAO module as a folder not jar. below is the screen shot of Dependency Hierarchy of service module.

    enter image description here

  • TaouBen
    TaouBen over 5 years
    Where did you write it in the pom.xml file ?
  • Vivek
    Vivek over 3 years
    XML Parser doesn't require elements to be in specific order within the same level. How can this be a possible solution?
  • Leonardo
    Leonardo about 3 years
    From Eclipse use Run As > Maven build, set goals on clean install.