41

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

Sunil Singh
  • 11,001
  • 2
  • 27
  • 48
Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126
  • The groupId in your parent does not match the groupId referenced? – Gyro Gearless Jul 10 '14 at 10:12
  • @GyroGearless thanks, the parent group id is incorrect in post, other wise in project its same. – Harmeet Singh Taara Jul 10 '14 at 10:17
  • The things you marked in Eclipse output is the workspace resolution in Eclipse. How does your folder strucuture on your hard disk look like? – khmarbaise Jul 10 '14 at 10:22
  • the folder structure is `D:\luna_workspace\empire_club\empirecl`. – Harmeet Singh Taara Jul 10 '14 at 10:24
  • it's cause of your root com.netsol:empirecl:pom:0.0.1-SNAPSHOT not installed inside .m2 file. it happen with me when tried to install only sub package needed so I tried to install all the packages and compile worked fine so notice that root package wasn't installed was the difference. – UN..D Dec 26 '22 at 20:08

8 Answers8

38

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

declension
  • 4,110
  • 22
  • 25
4

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

Sultan1991
  • 101
  • 6
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>
BStill
  • 894
  • 1
  • 9
  • 33
  • XML Parser doesn't require elements to be in specific order within the same level. How can this be a possible solution? – Vivek Jan 10 '21 at 01:07
1

For me, adding the following block of code under <dependency management><dependencies> solved the problem.

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.el</artifactId>
    <version>3.0.1-b06</version>
</dependency>
Suraj
  • 2,253
  • 3
  • 17
  • 48
1

This what worked for me - Go to Java build path --> Order and Export(check JRE system libraries and maven dependencies) in my case these 2 were unchecked.

0

My solution:

  1. remove all projects in current workspace
  2. import all again
  3. maven update project (Alt + F5) -> Select All and check Force Update of Snapshots/Releases
  4. maven build (Ctrl + B) until there is nothing to build

It worked for me after the second try.

WhiteCherry
  • 127
  • 9
0

Check with your VPN connection, if you are working in home.

  • 2
    This is no Answer, but a question to the author. Please write things like this as a comment on the question. – 3Fish May 27 '22 at 10:05
-2

Delete or close all other projects, and restart netbeans IDE, and try again.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72