mvn 小的知识点

来源:互联网 发布:如何成为英雄知乎 编辑:程序博客网 时间:2024/06/05 10:06

1. 关于maven插件配置 groupId 缺省的原因

用eclipse 打开 maven项目的pom文件,发现里面的部分插件都是如下:
xml
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
........
</plugin>

没有写 groupId ,原来maven 在处理的时候,默认给添加 org.apache.maven.plugins ,默认值就是这个!
maven 的插件来源主要来源于maven插件库
codehaus.org(老站点关闭) 点击为新的站点
所以如果不写 默认的值就为 org.apache.maven.plugins

2. maven中dependencyManagement和dependency的使用

这两个配置多用于父子模块中而且有多个子模块
当多个子模块共同依赖同一个项目(比如junit),那么就可以在父模块中添加
xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

这样之后,在子模块中还是不能查找到。
那么就在父模块中添加对junit的依赖
xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

这样每一个子模块都能获取到junit的依赖。
有利于对所有子模块共有的依赖做统一管理,版本号的更改。如果某个子项目单独换版本号,直接使用覆盖掉 version 就行了
xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>xxxx</version>
</dependency>
</dependencies>

0 0