Search code examples
javamavenmaven-module

Could not resolve dependencies for a Module Based Maven project


I am facing a problem while building a Maven module. I am following module-based architecture, I have a parent project named Bikewale and it's child modules named Bike-repo, Bike-service, and Bike-web. When I am trying to add Bike-repo dependency in Bike-service's pom file I am facing Maven Build Failure error saying:

[ERROR] Failed to execute goal on project Bike-service: Could not resolve dependencies for project ab.sp:Bike-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at ab.sp:Bike-repo:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for ab.sp:Bike-repo:jar:0.0.1-SNAPSHOT: Could not find artifact ab.sp:Bikewale:pom:0.0.1-SNAPSHOT -> [Help 1]

Although I checked in my .m2 repository that whether Bike-repo is present there or not, and it is present there. I was not facing this issue in my previous projects.Screenshot of .m2 repository

Bike-repo's 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>
  <parent>
    <groupId>ab.sp</groupId>
    <artifactId>Bikewale</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>Bike-repo</artifactId>
</project>

Bike-service's pom.xml:

where I am adding dependency of Bike-service:

<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>ab.sp</groupId>
        <artifactId>Bikewale</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>Bike-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>ab.sp</groupId>
            <artifactId>Bike-repo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

Solution

  • You're missing the artifact ab.sp:Bikewale:pom:0.0.1-SNAPSHOT. That is the parent pom.

    If you do a 'mvn install' in the parent directory, it should install first the parent pom, then the Bike-repo pom and jar, and then the Bike-service pom and jar.