1. 两个操作
(1) maven的JVM参数的设置方法
Linux:在~/.bash_profile文件中添加
export MAVEN_OPTS="-Xms512m -Xmx1024m"
Windows:如下图
(2) 用户级别的maven配置
把MAVEN_HOME/conf/seettings.xml cp 到 ~/.m2/下,在.m2下的settings.xml中所作的配置就是用户级别的配置,而直接编辑MAVEN_HOME/conf/seettings.xml所作的配置是全局的配置
2. 涉及的maven命令
[mvn -v]: 查看maven版本
[mvn -h]: 查看帮助
[mvn help:system]: 查看java的系统属性和环境变量
[mvn help:active-profiles]: 查看激活的profile
[mvn help:all-profiles]: 列出所有的profile
[mvn help:effective-pom]: 查看项目的所有pom元素(包括父元素中的默认配置)
[mvn clean/compile/test/package/install/deploy]: maven的不同阶段的命令,可以互相组合使用
[mvn archetype:generate]: 创建项目骨架
[mvn dependency:list]: 显示项目中所有已解析依赖
[mvn dependency:tree]: 查看当前项目的依赖树
[mvn dependency:analyze]: 分析项目依赖
[mvn clean install-U]: 强制maven检查更新
[mvn help:describe -Dplugin=org.apache.maven.plugins:maven-source-plugin:3.0.1 -Ddetail]: 查看某插件的详细信息
[mvn help:describe -Dplugin=source]: 上一个命令的简写
[mvn help:describe -Dplugin=compile -Dgoal=compile]: 只查看goal相关的信息
[mvn install -Dmaven.test.skip=true]: 构建时跳过测试(不编译测试代码,不运行测试代码)
[mvn package -DskipTests]: 构建时跳过测试(编译测试代码,不运行测试代码)
[mvn clean install -pl module1,module2]: 构建指定的模块
[mvn clean install -pl module -am]: 构建指定模块及其依赖的模块
[mvn clean install -pl module -amd]: 构建指定模块及依赖其的模块
[mvn clean install -rf module]: 在完整的反应堆构建顺序基础上指定从哪个模块开始构建
[mvn clean install -pl module1 -amd -rf module2]: 构建module1以及依赖其的模块,并且从module2开始构建
[mvn clean install -P dev]: 激活id为dev的profile
[mvn clean install -P profile1,profile2]: 激活多个profile
[mvn clean install -Dkey=value]: 设置系统属性值
[mvn test -Dtest=A]: 测试A类
[mvn test -Dtest=A*B]: 测试以A开头B结尾的类
[mvn test -Dtest=A,B]: 测试A类和B类
[mvn test -Dtest=A*B,C]: 测试以A开头B结尾的类以及C类
[mvn test -Dtest -DfailIfNoTests=false]: 即使没有运行测试也不要报错
[mvn cobertura:cobertura]: 生成测试覆盖率报告,文件为target/site/cobertura/index.html
[mvn jetty:run]: 使用jetty-maven-plugin进行测试
[mvn jetty:run -Djetty.port=9999]: 启动jetty服务进行测试,并指定端口号
[mvn cargo:start]: 发布war包到本地服务器
[mvn cargo:deploy]: 发布war包到远程服务器
[mvn release:clean]: 发布新版本前clean
[mvn release:prepare]: 发布新版本前的准备工作
[mvn release:prepare -DautoVersionSubmodules=true]: 子模块与父模块使用相同的版本
[mvn release:rollback]: prepare后如果发现错误,可以回滚
[mvn release:perform]: 发布新版本
[mvn release:branch -DbranchName=0.0.1 -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false]: 创建分支,分支使用新版本,不更新主干(trunk)的代码
[mvn clean deploy -Dgpg.passphrase=passwd]: 发布已经签名的构件
[mvn gpg:sign-and-deploy-file -DgroupId=com.bonc.rdpe -DartifactId=maven001 -Dversion=0.0.1-SNAPSHOT -Dpomfile=target/maven001-0.0.1-SNAPSHOT.pom -Dfile=target/maven001-0.0.1-SNAPSHOT.jar -Durl=http://192.168.138.129:8081/repository/maven-snapshots/ -DrepositoryId=nexus-snapshots]: 发布没有签名的文件并对其签名
[mvn site]: 生成站点
[mvn site:stage -DstagingDirectory=D:\tmp]: 把站点预发布到某个临时文件夹下
3. settings.xml文件内容总结
path/to/maven/repo
true
false
org.eclipse.jetty
com.your.plugins
dev3-proxy
true
http
root
root
172.16.13.185
9999
https://repo.maven.apache.org/maven2|*.google.com
nexus-releases
hadoop
hadoop
nexus-snapshot
hadoop
hadoop
Public Repositories
Public Repositories
*
http://172.16.13.185:9000/nexus/content/groups/public/
alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
central
jdk-1.8
true
1.8
1.8
1.8
1.8
profile1
com.mysql.jdbc.Driver
jdbc:mysql://192.168.138.101:3306/test
dev
dev-pwd
profile2
one.of.system.property
expected.value
profile3
Windows 10
Windows
amd64
10.0
profile4
x.properties
y.properties
dev
4. 一份可以直接复制使用的settings.xml文件
只需要修改仓库路径和JDK版本即可直接使用:
/path/to/local/repo
true
false
alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
central
jdk-1.8
true
1.8
1.8
1.8
1.8
5. pom.xml文件内容总结
4.0.0
com.bonc.rdpe
maven001
0.0.1-SNAPSHOT
jar
maven001
2.7.6
4.7
2.3.0
2.5.6
central
Central Repository
https://repo.maven.apache.org/maven2
default
true
never
warn
false
dev3-repository
Dev3 Release Repository
http://172.16.13.185:9000/nexus/content/repositories/releases/
dev3-snapshots-repository
Dev3 Snapshot Repository
http://172.16.13.185:9000/nexus/content/repositories/snapshots/
org.springframework
spring-core
${springframework.version}
org.springframework
spring-beans
${springframework.version}
org.springframework
spring-context
${springframework.version}
org.springframework
spring-context-support
${springframework.version}
junit
junit
${junit.version}
test
com.bonc.rdpe
account-xxx
0.0.1-SNAPSHOT
pom
import
org.apache.spark
spark-sql_2.11
${spark.version}
jar
system
${JAVA_HOME}/lib/rt.jar
true
org.apache.hadoop
hadoop-client
org.apache.hadoop
hadoop-client
${hadoop.version}
dev
com.mysql.jdbc.Driver
jdbc:mysql://192.168.138.101:3306/dev
dev
dev-pwd
dev
com.mysql.jdbc.Driver
jdbc:mysql://192.168.138.101:3306/test
test
test-pwd
org.apache.maven.plugins
maven-compiler-plugin
1.8
org.apache.maven.plugins
maven-resources-plugin
UTF-8
${project.basedir}/target
${project.build.directory}/classes
${project.artifactId}-${project.version}
${project.build.directory}/test-classes
${project.basedir}/src/main/java
src/main/scripts
${project.basedir}/src/test/java
${project.basedir}/src/main/resources
true
${project.basedir}/src/test/resources
true
org.apache.maven.plugins
maven-compiler-plugin
1.8
true
org.apache.maven.plugins
maven-source-plugin
3.0.1
attach-source
verify
jar-no-fork
org.apache.maven.plugins
maven-shade-plugin
3.1.1
package
shade
com.bonc.rdpe.maven001.HelloWorld
org.apache.maven.plugins
maven-jar-plugin
3.1.0
test-jar
org.apache.maven.plugins
maven-war-plugin
3.2.2
src/main/webapp
true
**/*.css
**/*.js
org.apache.maven.plugins
maven-surefire-plugin
2.22.0
${project.build.directory} est-reports
true
**/*Tests.java
**/*ServiceTest.java
**/ArrayTest.java
testng.xml
group1
6. 超级pom
4.0.0
central
Central Repository
https://repo.maven.apache.org/maven2
default
false
central
Central Repository
https://repo.maven.apache.org/maven2
default
false
never
${project.basedir}/target
${project.build.directory}/classes
${project.artifactId}-${project.version}
${project.build.directory}/test-classes
${project.basedir}/src/main/java
${project.basedir}/src/main/scripts
${project.basedir}/src/test/java
${project.basedir}/src/main/resources
${project.basedir}/src/test/resources
maven-antrun-plugin
1.3
maven-assembly-plugin
2.2-beta-5
maven-dependency-plugin
2.8
maven-release-plugin
2.5.3
${project.build.directory}/site
release-profile
performRelease
true
true
maven-source-plugin
attach-sources
jar
true
maven-javadoc-plugin
attach-javadocs
jar
true
maven-deploy-plugin
true