1.常用命令
mvn -v 查看版本信息
compile 编译
test 测试
package 打包
clean 删除target目录
install 安装jar包到本地仓库
2.maven 的仓库
Maven中的仓库分为两种:Snapshot快照仓库和Release发布仓库。
Snapshot快照仓库用于保存开发过程中的不稳定版本.
Release正式仓库则是用来保存稳定的发行版本。
<version>0.1-SNAPSHOT</version>
3.创建目录的两种方式
1.archetype:generate 按照提示进行选择
2.archetype:generate -DgroupId=组织名, 公司名字的反写+项目名
-DartifactId=项目名-模块名
-Dversion=版本号
-Dpackage=代码所在的包名
4.更改maven默认jdk版本号
1.右键properties更改
只更改当前模块,下次新建还要更改
2.更改settings.xml文件,补充这段代码
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
5.聚合,依赖
聚合,方便项目多个模块install等操作
<packaging>pom</packaging>
<modules>
<module>../shuyuan-fuzi(模块名)</module>
<module>../shuyuan-limanman(模块名)</module>
<module>../shuyuan-ningque(模块名)</module>
</modules>
依赖
以junit为例
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>3.8.1</junit.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
其他模块:
<parent>
版本号+坐标
</parent>
6.maven依赖冲突(短路优先)
例子:模块B依赖模块A模块C依赖模块B
A,B都有插件junit 但版本不一样,C优先B的junit的版本号