父子模块的pom文件里会涉及dependencies、dependecyManagement、packaging元素、properties元素。
子模块里必须有parent元素,如下所示:
<parent><groupId>org.apache</groupId><artifactId>plugin</artifactId><version>1.3.0-SNAPSHOT</version>
</parent>
父模块里会有modules元素,如下所示:
<modules><module>provider</module><module>consumer</module><module>api</module>
</modules>
1、packaging元素
父模块里的packaging必须是pom。子模块一般是jar,但也可以是pom,此时子模块仅包含一些依赖,没有代码,或者也是父模块。
2、dependencies元素
一般出现在父模块的pom文件里。被dependencies包含的依赖会被子项目无条件继承下去,无需子项目显示指定。用法如下所示:
<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.version}</version></dependency>
</dependencies>
3、dependecyManagement元素
一般出现在父模块的pom文件里。被dependencyManagement包含的依赖不会被子项目直接继承下去,子项目需要显示写出依赖,当然可以省略version和scope(从父项目中继承)。用法如下:
<dependencyManagement><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.version}</version></dependency></dependencies>
</dependencyManagement>
4、mvn命令
在父项目的根目录下执行mvn clean compile,那么该父项目及其子项目都会被先清理再编译,并且是按照实际的依赖关系对子模块重排序,以确保所有模块都能顺利完成构建(参见)。
5、properties元素
properties元素通常用来定义一些常量,会被子模块无条件的继承过去。可用来定义版本号,这样可以同时修改多个依赖的版本号。
本文发布于:2024-02-01 13:33:05,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170676558436957.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |