maven基本使用

一、常用命令

1.跳过测试

运行时:

1
mvn -Dmaven.test.skip=true

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

2.下载依赖的源码包

1
mvn dependency:sources

3.本地打包

1
mvn clean compile install

如果需要更新相关依赖,例如SNAPSHOT,可以加-U

1
mvn -U

4.运行测试类

1
mvn test

5.deploy到仓库

1
mvn clean compile deploy

setting.xml配置中要有对应仓库的id和密码

6.依赖相关

(1) 依赖分析

1
2
mvn dependency:analyze
mvn dependency:list

需要如下插件

1
2
3
4
5
6
7
8
9
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <overWriteReleases>true</overWriteReleases>
        <overWriteSnapshots>true</overWriteSnapshots>
    </configuration>
</plugin>

(2) 下载依赖到本地

1
mvn dependency:copy-dependencies

二、maven配置

1.本地仓库