• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
蛋定好时光
博客园    首页    新随笔    联系   管理    订阅  订阅
Maven中的DependencyManagement和Dependencies

Maven 使用dependencyManagement 元素来提供了一种管理依赖版本号的方式。通常会在一个组织或者项目的最顶层的父POM 中看到dependencyManagement 元素。使用pom.xml 中的dependencyManagement 元素能让
所有在子项目中引用一个依赖而不用显式的列出版本号。Maven 会沿着父子层次向上走,直到找到一个拥有dependencyManagement 元素的项目,然后它就会使用在这个dependencyManagement 元素中指定的版本号。

 

例如在父项目里:

 1 <dependencyManagement>
 2         <dependencies>
 3             <dependency>
 4                 <groupId>junit</groupId>
 5                 <artifactId>junit</artifactId>
 6                 <version>3.8.1</version>
 7                 <scope>test</scope>
 8             </dependency>
 9             <dependency>
10                 <groupId>org.springframework</groupId>
11                 <artifactId>spring-webmvc</artifactId>
12                 <version>4.3.2.RELEASE</version>
13             </dependency>
14             <dependency>
15                 <groupId>org.springframework</groupId>
16                 <artifactId>spring-context</artifactId>
17                 <version>4.3.2.RELEASE</version>
18             </dependency>
19         </dependencies>
20     </dependencyManagement>

然后在子项目里就可以不指定版本号,例如:

 1 <dependencies>
 2         <dependency>
 3             <groupId>org.springframework</groupId>
 4             <artifactId>spring-webmvc</artifactId>
 5         </dependency>
 6         <dependency>
 7             <groupId>org.springframework</groupId>
 8             <artifactId>spring-context</artifactId>
 9         </dependency>
10         <dependency>
11             <groupId>javax.servlet</groupId>
12             <artifactId>javax.servlet-api</artifactId>
13             <version>3.1.0</version>
14             <scope>provided</scope>
15         </dependency>
16     </dependencies>

 

posted on 2016-11-22 15:05  蛋定好时光  阅读(1103)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3