美文网首页maven
maven子模块操作 dependencyManagement和

maven子模块操作 dependencyManagement和

作者: 奔跑的Robi | 来源:发表于2019-09-26 10:05 被阅读0次

当项目中有很多子模块时,通过父项目的pom文件来管理一些通用依赖的版本号
父项目的pom文件中使用<modules><module>标签来引入子模块
在子模块中使用<parent>标签,把父项目的groupId,artifactId写上

在父项目中这样声明

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.netty</groupId>
                <artifactId>netty-all</artifactId>
                <version>4.1.41.Final</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

那么子项目中不会真的引入netty,需要在子项目中这样写

<dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
 </dependency>

可以看到子项目不需要再写版本号了,这样可实现版本号的统一
如果子项目中还是写了版本号,就会优先使用子项目中写的版本

如果在父项目中直接使用dependencies的话,就会默认全部子模块都引入了
使用dependencyManagement只是声明,子模块中不写dependencies还是不会引入的

相关文章

网友评论

    本文标题:maven子模块操作 dependencyManagement和

    本文链接:https://www.haomeiwen.com/subject/itvructx.html