简体   繁体   中英

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?

The "parent" pom should be an "aggregator", that is it should include modules of both dw-web and dw-test and itself have a packaging pom:

<project>
    ...
     <packaging>pom</packaging>

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

With this setup, maven will automatically resolve the dependency graph and compile everything in the correct order ( dw-web first, and dw-test afterwards).

So make sure that you have such a setup. Of course there can be other reasons as well, the best would be adding relevant code snippets from all the pom files in the question.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM