对于几乎在每个模块都需要引用的依赖,去各自的模块配置中添加太麻烦了,就想着在父模块中添加,然后在子模块中继承就可以了。首先,需要注意:
父模块中要有对应的模块标签:
<modules>
<module>my-querydsl-web</module>
<module>my-querydsl-service</module>
<module>my-querydsl-entity</module>
</modules>
子模块要指定对应的父模块标签:
<parent>
<groupId>com.wzh</groupId>
<artifactId>my-querydsl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/>
</parent>
这样父模块中添加的依赖在子模块中就可以直接使用
另外需要注意的区别,如下依赖可以被子模块继承
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
</dependencies>
下面标签的依赖不会被子模块继承
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
</dependencies>
</dependencyManagement>
在Maven项目中,为了简化依赖管理,可以在父模块定义公共依赖,子模块通过继承父模块来共享这些依赖。父模块需声明子模块列表,而子模块需指定父模块。直接在`<dependencies>`标签中的依赖会被子模块继承,而在`<dependencyManagement>`中的依赖只会提供版本管理和统一,不会自动引入到子模块。
6264

被折叠的 条评论
为什么被折叠?



