maven 继承关系和聚合
2024-08-26 15:23:51
maven继承管理 让版本的管理只在一个地方改变
modules用于聚合,把执行的项目都放到同一的地方用module包括,可以省去一个个项目去mvn install,这样可以所有项目一次聚合 mvn install
传递性依赖原则:
A-->B
A-->C
1.路径最近者优先
2.路径相同,第一声明者优先
注意:
1.dependencyManagement中定义的依赖子module不会共享
2.dependencies中定义的依赖子module可以共享
dependencyManagement的使用 就是方便管理版本,子项目中要引入group id和atifact id
在parent项目的pom.xml配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <name>Parent</name>
<url>http://maven.apache.org</url>
<!--聚合-->
<modules>
<module>../Hello</module>
<module>../HelloFriend</module>
<module>../MakeFriends</module>
<module>../Web</module>
</modules> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <!--定义了依赖的关系,让其他项目继承这些包,不用写版本,同一控制了-->
<dependencyManagement> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>HelloFriend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>MakeFriends</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement> <distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8080/nexus-2.1.2/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8080/nexus-2.1.2/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement> </project>
Hello.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <artifactId>Hello</artifactId> <parent>
<groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<dependencies>
<!--不用写版本了 parent那里同一控制了-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies> </project>
HelloFriend pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <artifactId>HelloFriend</artifactId> <name>HelloFriend</name> <parent>
<groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
</dependency>
</dependencies>
</project>
最新文章
- Response.Redirect引起的性能问题分析
- [mobi文件格式详细介绍一]_[资料篇]
- asp.net上传文件超过了最大请求长度[转]
- jquery中prop()与attr()方法的区别
- latex+bibtex+jabref(zz)
- Mac 显示和隐藏 隐藏文件
- iOS - UIProgressView
- AsyncSocket的使用
- POJ1789 Truck History(prim)
- CGRectInset CGRectoffset UIEdgeInsetsInsetRect 这三个函数的使用情况
- Java开发工具与程序调试
- iOS开发 编辑框被系统弹出的软键盘遮挡问题
- VHDL设计问题
- hdu_5777_domino(贪心)
- HDU1686:Oulipo
- 13 用Css做下拉菜单
- deeplearning.ai 构建机器学习项目 Week 1 机器学习策略 I 听课笔记
- C语言队列(数组内核)
- 【Java8】@FunctionalInterface
- CSS3系列教程:HSL 和HSL
热门文章
- struts2 <;s:select>;标记取包含map的list的值
- 手机网站和PC网站兼容的响应式网页设计
- sudo:抱歉,您必须拥有一个终端来执行 sudo 解决办法;ssh执行sudo命令的方法;给用户增加sudo免密权限
- 【Codeforces】【#295】【Div.2】
- Informatica 常用组件Source Qualifier之八 Distinct
- UVA 400 (13.08.05)
- Android组件之BroadCast简单实践
- Binary Tree Inorder Traversal leetcode java
- file not found app文件
- magento upsell from cur_category