Maven multi module project cannot find sibling module

后端 未结 2 1457
心在旅途
心在旅途 2020-12-06 16:54

I can\'t seem to get Maven to find a sibling\'s module in a multi-module project.

I\'ve run mvn clean install in all modules.

Here\'s the setu

相关标签:
2条回答
  • 2020-12-06 17:17

    When you are building a multi-module Maven project, you need to run Maven commands from the root POM. This means you need to run mvn clean install on Product's pom.xml.

    The error you are getting is expected: you are only building Model. In Model's POM, Maven sees that there is a dependency on MagniCompCommon so it tries to look for that dependency. First, it searches in your local repo: it fails to find it there since you did not install MagniCompCommon before. As a result, it looks for it in the predefined remote repositories (and also fails to find it).

    You would be able to circumvent this by first running mvn clean install on MagniCompCommon's POM, then on Model POM but this is much easier done by invoking Maven directly on the root POM. It will correctly build every modules in the right order (since Model depends on MagniCompCommon, it will build MagniCompCommon first, then Model).

    As a side note, you can remove the line <packaging>jar</packaging> because this is the default.

    0 讨论(0)
  • 2020-12-06 17:28

    I noticed MagniCompCommon pom doesnt specify a version

    <!-- <groupId>com.magnicomp.common</groupId> -->
    <artifactId>MagniCompCommon</artifactId>
    <packaging>jar</packaging>
    

    And in Product pom, you're referencing version 1.0

    <dependency>
        <groupId>com.magnicomp</groupId>
        <artifactId>MagniCompCommon</artifactId>
        <version>1.0</version>
    </dependency>
    

    Have you tried specifying version 1.0 in MagniCompCommon pom?

    0 讨论(0)
提交回复
热议问题