apache maven是一个用于项目构建和依赖管理的工具。
添加archetype
https://repo1.maven.org/maven2/archetype-catalog.xml
更改本地仓库存储位置:修改配置文件${user.home}/.m2/settings.xml或 $MAVEN_HOME/conf/setting.xml中的内容
<localRepository>...
mvn archetype:generate
会非常慢,搜索了本地和远程太多archetype,而加上-DarchetypeCatalog=local
将只搜索${user.home}/.m2/archetype-catalog.xml中定义的本地archetype,会大大提高速度。
mvn archetype:crawl
会根据远程数据生成本地archetype目录$maven_localRepository/archetype-catalog.xml。
download jar, sources, javadoc
mvn dependency:get -Dartifact=groupId:artifactId:version[:packaging[:classifier]]
eg. mvn dependency:get -Dartifact=mysql:mysql-connector-java:LATEST
mvn dependency:get -Dartifact=mysql:mysql-connector-java:LATEST:jar:sources
download sources/javadoc
mvn dependency:sources -DincludeGroupIds=grouId1,groupId2... -Dclassifier=sources
mvn dependency:get -Dartifact=mysql:mysql-connector-java:LATEST:jar:sources
download sources for each of dependencies in pom.xml
mvn dependency:sources
mvn dependency:resolve -Dclassifier=sources
download javadoc
mvn dependency:get -Dartifact=mysql:mysql-connector-java:LATEST:jar:javadoc
# download javadoc for each of dependencies in pom.xml
mvn dependency:sources -Dclassifier=javadoc
mvn dependency:resolve -Dclassifier=javadoc
copy dependecies
mvn dependency:copy -Dartifact=g:a:v -o -DrepoUrl=file://path/to/your/repo
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=groupId:artifactId:version[:packaging][:classifier] -DoutputDirectory=[target]
mvn dependency:build-classpath [-Dmdep.outputFile=/path/file](输出到文件)
mvn基本的几个jar包相关命令:mvn clean
清除target/
编译文件夹mvn compile
编译源码mvn package
编译并打包为jar文件mvn install
将jar文件安装到本地repomvn deploy
根据pom.xml中的信息,将jar包部署到远程repo
跳过测试mvn -DskipTests
指定pom文件mvn -f some-pom.xml
插件描述文档
mvn help:describe -Ddetail -Dplugin=<plugin-name> 或 -Dcmd=<plugin>:<phase>
# mvn help:describe -Dplugin=exec
# mvn help:describe -Dcmd=install:install-file
# mvn help:describe -Dplugin=g:a:v
关闭mvn的日志输出mvn -q
生成源码jar包mvn source:jar
maven 3.x super pom位置
$M2_HOME/lib/maven-model-builder-3.x.jar:/org/apache/maven/model/pom-4.0.0.xml
######## unresolved #########
list addable dependencies in local repository
list addable dependencies all available repositories
list achetypes
(不可用)get file path of artifact
mvn dependency:location -Dartifact=g