Search code examples
javamavenspring-bootpom.xmlparent-pom

failed to resolve dependencies in maven multi module project


I am posting this question even though there are other questions on this. However, I did not find any solution so far on this, hence posting this question.

I am getting this error :

Could not resolve dependencies for project vehicle-tracker:vehicle-simulator:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at vehicle-tracker:common-libs:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for vehicle-tracker:common-libs:jar:0.0.1-SNAPSHOT: Could not find artifact vehicle-tracker:vehicle-tracker:pom:0.0.1-SNAPSHOT

common-libs jar is available under

.m2\repository\vehicle-tracker\common-libs\0.0.1-SNAPSHOT

The project I am trying to build is dependent over common-libs jar but maven is failed to find in local maven repo.

I am attaching following POM.xml

Parent.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>vehicle-tracker</groupId>
  <artifactId>vehicle-tracker</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

  <dependencies>
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        </dependencies>
  <modules>
    <module>common-libs</module>
    <module>vehicle-simulator</module>
    <module>tracker-dashboard</module>
  </modules>

</project>

Common-libs POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>vehicle-tracker</groupId>
        <artifactId>vehicle-tracker</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../../vehicle-tracker</relativePath> <!-- lookup parent from repository -->
    </parent>
    <artifactId>common-libs</artifactId>
    <name>common-libs</name>
    <description>Common libraries for vehicle tracker</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

vehicle-simulator POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>vehicle-tracker</groupId>
        <artifactId>vehicle-tracker</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../../vehicle-tracker/</relativePath> <!-- lookup parent from repository -->
    </parent>
    <artifactId>vehicle-simulator</artifactId>
    <name>vehicle-simulator</name>
    <description>vehicle simulator for application</description>

    <properties>
        <java.version>1.8</java.version>
        <swagger-version>2.9.2</swagger-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger-version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger-version}</version>
        </dependency>

        <dependency>
            <artifactId>common-libs</artifactId>
            <version>0.0.1-SNAPSHOT</version><!--${project.version}-->
            <groupId>vehicle-tracker</groupId><!-- ${project.groupId} -->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

I am not able to find where I am doing mistake in POM or else where ...so not able to build project vehicle-tracker.


Solution

  • I resolved the build error. Actually I was putting below in common-libs module's POM.xml :

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    

    This should be in the POM.xml of commons-lib module as it is creating spring-boot jar. Hence dependency was not available for dependent module. After removing this block of configuration in POM.xml from commons-lib module, I am able to build the project without any issue(s).

    Thank U All for looking in to this. Just sharing this if any one having would face this knowingly or unknowingly.