Maven doesn't recognize sibling modules when running mvn dependency:tree

后端 未结 8 2044
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:31

I\'m trying to set up a multi-module Maven project, and the inter-module dependencies are apparently not being set up correctly.

I have:



        
相关标签:
8条回答
  • 2020-12-02 05:25

    In a Maven module structure like this:

    - parent
      - child1
      - child2
    

    You will have in the parent pom this:

    <modules>
      <module>child1</module>
      <module>child2</module>
    </modules>
    

    If you now depend on child1 in child2 by putting the following in your <dependencies> in child2:

    <dependency>
      <groupId>example</groupId>
      <artifactId>child1</artifactId>
    </dependency>
    

    You will receive an error that the JAR for child1 cannot be found. This can be solved by declaring a <dependencyManagement> block including child1 in the pom for parent:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>example</groupId>
          <artifactId>child1</artifactId>
          <version>${project.version}</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    child1 will now be build when you run a compile or package etc. goal on parent, and child2 will find child1's compiled files.

    0 讨论(0)
  • 2020-12-02 05:26

    Realizing this is an older thread but it seems that either the tool evolved or this might have been missed the first time around.

    It is possible to perform a build that makes dependencies resolved without installing by doing a reactor build.

    If you start your build in the parent that describes the module structure of your project then your dependencies between your modules will be resolved during the build itself through the internal Maven reactor.

    Of course this is not the perfect solution since it does not solve the build of a single individual module within the structure. In this case Maven will not have the dependencies in his reactor and will bee looking to resolve it in the repository. So for individual builds you still have to install the dependencies first.

    Here is some reference describing this situation.

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