Maven:子模块不能继承父模块的依赖项 [英] Maven: child module can not Inheritance parent module's dependencies

查看:106
本文介绍了Maven:子模块不能继承父模块的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的父母pom

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.fish56</groupId>
    <artifactId>MavenModules</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>dao</module>
    </modules>
    <packaging>pom</packaging>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.6</version>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

这是我的子模块的pom

this is my child module's pom

    <parent>
        <artifactId>MavenModules</artifactId>
        <groupId>com.github.fish56</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>dao</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>

我希望子模块可以继承父模块的依赖关系,但是失败了.

I wish child module can inheritance parent's dependencies, but it failed.

我不能在孩子的pom中使用lombok或junit.

I can not use lombok or junit in my child pom.

这是我的文件树

.
├── dao
│   ├── pom.xml
│   ├── src
│   └── target
├── pom.xml

我认为应该有一种方法可以使所有模块分片一些依赖,但是我找不到解决方法.

I think there should a way the make some dependencies to be shard ammon all modules, But I can not find the solution.

推荐答案

在父 POM 中,< dependencies> <之间的主要区别; dependencyManagement> 如下:

工件将始终作为子模块的依赖项包括在内.

Artifacts specified in the <dependencies> section will ALWAYS be included as dependencies of the child module(s).

< dependencyManagement> 部分中指定的工件,仅在子模块中包含(如果它们也在< dependencies> <子模块本身的/code>部分.

Artifacts specified in the <dependencyManagement> section, will only be included in the child module if they were also specified in the <dependencies> section of the child module itself.

请在以下链接中找到更多信息:

Please find more at following link:

dependencyManagement和Maven中的依赖项之间的区别

这篇关于Maven:子模块不能继承父模块的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆