Search code examples
javaeclipsejenkinsmaven-2multi-module

Error resolving dependency for maven multi module project


I have set up a multi module maven project with two modules, dw-web and dw-test.

Parent
  - dw-web
  - dw-test

The parent pom:

<modelVersion>4.0.0</modelVersion>

    <groupId>com.dw</groupId>
    <artifactId>dw-parent</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <modules>
        <module>dw-web</module>
        <module>dw-test</module>
    </modules>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <release>11</release>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

dw-test pom:

<modelVersion>4.0.0</modelVersion>
<artifactId>dw-test</artifactId>
<parent>
    <groupId>com.dw</groupId>
    <artifactId>dw-parent</artifactId>
    <version>1.0</version>
</parent>

<dependencies>
  <dependency>
    <groupId>com.dw</groupId>
    <artifactId>dw-web</artifactId>
    <version>1.0</version>
  </dependency>
</dependencies>

dw-web pom:

<modelVersion>4.0.0</modelVersion>
<artifactId>dw-web</artifactId>
<packaging>jar</packaging>
<version>1.0</version>

<parent>
    <groupId>com.dw</groupId>
    <artifactId>dw-parent</artifactId>
    <version>1.0</version>
</parent>

Since im new to maven i used this guide as a reference: https://books.sonatype.com/mvnex-book/reference/multimodule-sect-simple-web.html. It suggests to import the module that dw-test depends on (dw-web) to import with this dependency declaration:

<dependency>
  <groupId>com.dw</groupId>
  <artifactId>dw-web</artifactId>
  <version>1.0</version>
</dependency>

When executing mvn clean install on the parent pom the import for this dependency fails on my test server, but not on my machine.

Failed to execute goal on project dw-test: Could not resolve dependencies for project com.dw:dw-test:jar:1.0: Failure to find com.dw:dw-web:jar:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced

Some resources suggest that either the local m2 repository or my IDE(eclipse) seems to cache the generated jar? Do i have to import the jar via the system tag and then point maven to the jar or alternatively upload it to a nexus repository in order to resolve the dependency errors? Isn't the multi module project supposed to resolve any dependencies between these projects without having to up and then download the build projects to an external entity?


Solution

  • The solution to the problem was that I had declared dw-web in the parent pom both as a module and dependency. After removing the dependency declaration the project compiled.