maven 常用命令
创建一个简单的maven项目
mvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-site \
-DgroupId=com.mycompany.app \
-DartifactId=my-app-site
maven 处理依赖的方式
使用构建命令
package 和 install 两个命令都会下载依赖包.
clean
clean remove the target filder
package
package will compile your code and also package it. For example, if your pom says the project is a jar, it will create a jar for you when you package it and put it somewhere in the target directory (by default).
install
install will compile and package, but it will also put the package in your local repository. This will make it so other projects can refer to it and grab it from your local repository.
install phase comes after package phase
update repository after adding dependency
If you want to only download dependencies without doing anything else, then it’s:
mvn dependency:resolve
Or to download a single dependency:
mvn dependency:get -Dartifact=groupId:artifactId:version
If you need to download from a specific repository, you can specify that with -DrepoUrl=…
mvn install (or mvn package) contains update repository
mvn compile to download compile time dependencies or mvn test for compile time and test dependencies
other
- 显示一级依赖
mvn dependency:tree
- -Dverbos 显示多级依赖
mvn dependency:tree -Dverbos
- -Dincludes 指定包
- -Dexcludes 排除指定包
找出依赖关系后在pom.xml文件中利用标签\<exclusions>排除相应的依赖
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-dbmaintainer</artifactId>
<version>${unitils.version}</version>
<exclusions>
<!-- 排除相应的依赖 -->
<exclusion>
<artifactId>dbunit</artifactId>
<groupId>org.dbunit</groupId>
</exclusion>
<exclusion>
<artifactId>asm</artifactId>
<groupId>asm</groupId>
</exclusion>
</exclusions>
</dependency>