有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

maven多模块项目的java最佳方法

当我需要指定子模块与父模块的依赖关系时,我对多模块maven project有问题

这是我的pom配置。xml

父POM:

<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
    <module>childA</module>
    <module>childB</module>
</modules>

childA POM

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

<artifactId>childA</artifactId>

   <dependencies>
    <dependency>
        <groupId>com.parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    </dependencies>

ChildB POM

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

<artifactId>childB</artifactId>

在childB中运行mvn clean install时,我能够构建childB

我在生成带有错误消息的父和子时出错

ERROR] Failed to execute goal on project parent: Could not resolve dependencies for project com.parent:childA:jar:1.0-SNAPSHOT: Could not find artifact com.parent:parent:jar:1.0-SNAPSHOT -> [Help 1]

我需要在childA pom中增加依赖性。xml到父包,因为父包上有一些可用的类

我应该如何解决这个问题


共 (1) 个答案

  1. # 1 楼答案

    pom毫无意义

    它与依赖项父项和构建依赖项具有相同的工件:

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

    以及:

    <dependencies>
      <dependency>
        <groupId>com.parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
    </dependencies>
    

    第一:依赖解决方案永远不会成功,因为这是一个鸡和蛋的问题
    生成pom的父模块将仅在反应堆构建终止时可用,但它将仅在childA中的所有模块将终止其构建时终止

    第二:多模块maven项目和父模块被设计成pom,而不是jar
    将其声明为childA的依赖项符合哪些利益
    只需删除它并将其作为childA的父级

    I need added dependency inside childA pom.xml to parent package due to some classes available on parent package

    不需要将其指定为依赖项即可实现
    子项目从父项目继承了许多东西,包括依赖项