Maven 常用命令介绍

作者:範宗雲 来源:原创 发布时间:2015-04-08 归档:maven

开发环境 : JDK 7 Maven 3 Eclipse Luna
test  [ 运行测试 ]
mvn test
		    F:\dev\share\myapp>mvn test
			-------------------------------------------------------
			 T E S T S
			-------------------------------------------------------
			Running org.lychie.util.RandomUtilTest
			---> intSeed(0, 9) : 7
			---> boolSeed : true
			Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.085 sec
			
			Results :
			
			Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
			
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
-e  [ 显示错误详细信息 ]
mvn -e test
		    F:\dev\share\myapp>mvn -e test
			-------------------------------------------------------
			 T E S T S
			-------------------------------------------------------
			Running org.lychie.util.RandomUtilTest
			---> boolSeed : true
			---> intSeed(0, 9) : 0
			Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.093 sec <<< FAILURE!
			testIntSeed2(org.lychie.util.RandomUtilTest)  Time elapsed: 0.01 sec  <<< ERROR!
			java.lang.IllegalArgumentException
			        at java.util.concurrent.ThreadLocalRandom.nextInt(ThreadLocalRandom.java:145)
			        at org.lychie.util.RandomUtil.intSeed(RandomUtil.java:12)
			        at org.lychie.util.RandomUtilTest.testIntSeed2(RandomUtilTest.java:19)
			        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
			
			Results :
			
			Tests in error:
			  testIntSeed2(org.lychie.util.RandomUtilTest)
			
			Tests run: 3, Failures: 0, Errors: 1, Skipped: 0
			
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD FAILURE
			[INFO] ------------------------------------------------------------------------
		    
site  [ 生成站点文件 ]
mvn site ( 见 target/site 目录 )
package  [ 打包 ]
mvn package
		    F:\dev\share\myapp>mvn package
			-------------------------------------------------------
			 T E S T S
			-------------------------------------------------------
			Running org.lychie.util.RandomUtilTest
			---> intSeed(0, 9) : 1
			---> boolSeed : true
			Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.088 sec
			
			Results :
			
			Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
			
			[INFO]
			[INFO] Building jar: F:\dev\share\myapp\target\myapp-1.0.jar
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
install  [ 安装到本地仓库 ]
mvn install ( 见本地仓库 ${groupId}/${artifactId} 目录 )
		    F:\dev\share\myapp>mvn install
			-------------------------------------------------------
			 T E S T S
			-------------------------------------------------------
			Running org.lychie.util.RandomUtilTest
			---> boolSeed : false
			---> intSeed(0, 9) : 1
			Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.095 sec
			
			Results :
			
			Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
			
			[INFO]
			[INFO] Installing F:\dev\share\myapp\target\myapp-1.0.jar to F:\dev\repo\maven\org\lychie\myapp\1.0\myapp-1.0.jar
			[INFO] Installing F:\dev\share\myapp\pom.xml to F:\dev\repo\maven\org\lychie\myapp\1.0\myapp-1.0.pom
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
compile  [ 编译源代码 ]
mvn compile
		    F:\dev\share\myapp>mvn compile
			[INFO] Scanning for projects...
			[INFO] skip non existing resourceDirectory F:\dev\share\myapp\src\main\resources
			[INFO]
			[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myapp ---
			[INFO] Nothing to compile - all classes are up to date
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
test-compile  [ 编译测试代码 ]
mvn test-compile
		    F:\dev\share\myapp>mvn test-compile
			[INFO] Scanning for projects...
			[INFO] skip non existing resourceDirectory F:\dev\share\myapp\src\main\resources
			[INFO]
			[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ myapp ---
			[INFO] Nothing to compile - all classes are up to date
			[INFO]
			[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ myapp ---
			[INFO] Nothing to compile - all classes are up to date
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
			F:\dev\share\myapp>
		    
clean  [ 清除目标目录产生的结果 ]
mvn clean
		    F:\dev\share\myapp>mvn clean
			[INFO] Scanning for projects...
			[INFO]
			[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ myapp ---
			[INFO] Deleting F:\dev\share\myapp\target
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
-Dmaven.test.skip  [ 跳过测试 ]
mvn -Dmaven.test.skip package
		    F:\dev\share\myapp>mvn -Dmaven.test.skip package
			[INFO] Compiling 1 source file to F:\dev\share\myapp\target\classes
			[INFO]
			[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ myapp ---
			[INFO] Not copying test resources
			[INFO]
			[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ myapp ---
			[INFO] Not compiling test sources
			[INFO]
			[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ myapp ---
			[INFO] Tests are skipped.
			[INFO]
			[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myapp ---
			[INFO] Building jar: F:\dev\share\myapp\target\myapp-1.0.jar
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
-Dmaven.test.failure.ignore  [ 忽略测试失败 ]
mvn -Dmaven.test.failure.ignore package
		    F:\dev\share\myapp>mvn -Dmaven.test.failure.ignore package
			-------------------------------------------------------
			 T E S T S
			-------------------------------------------------------
			Running org.lychie.util.RandomUtilTest
			---> intSeed(0, 9) : 2
			---> boolSeed : false
			Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.108 sec <<< FAILURE!
			testIntSeed2(org.lychie.util.RandomUtilTest)  Time elapsed: 0.016 sec  <<< ERROR!
			java.lang.IllegalArgumentException
			        at java.util.concurrent.ThreadLocalRandom.nextInt(ThreadLocalRandom.java:145)
			        at org.lychie.util.RandomUtil.intSeed(RandomUtil.java:12)
			        at org.lychie.util.RandomUtilTest.testIntSeed2(RandomUtilTest.java:19)
			        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
			
			Results :
			
			Tests in error:
			  testIntSeed2(org.lychie.util.RandomUtilTest)
			
			Tests run: 3, Failures: 0, Errors: 1, Skipped: 0
			
			[ERROR] There are test failures.
			
			Please refer to F:\dev\share\myapp\target\surefire-reports for the individual test results.
			[INFO]
			[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myapp ---
			[INFO] Building jar: F:\dev\share\myapp\target\myapp-1.0.jar
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
dependency:sources  [ 依赖包源码 ]
mvn dependency:sources
		    F:\dev\share\myapp>mvn dependency:sources
			Downloading: https://repo.maven.apache.org/maven2/junit/junit/4.7/junit-4.7-sources.jar
			Downloading: https://repo.maven.apache.org/maven2/org/springframework/spring-aop/4.1.5.RELEASE/spring-aop-4.1.5.RELEASE-sources.jar
			[INFO]
			[INFO] The following files have been resolved:
			[INFO]    org.springframework:spring-web:jar:sources:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-webmvc:jar:sources:4.1.5.RELEASE:compile
			[INFO]    junit:junit:jar:sources:4.7:test
			[INFO]    aopalliance:aopalliance:jar:sources:1.0:compile
			[INFO]    org.springframework:spring-expression:jar:sources:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-core:jar:sources:4.1.5.RELEASE:compile
			[INFO]    commons-logging:commons-logging:jar:sources:1.2:compile
			[INFO]    org.springframework:spring-aop:jar:sources:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-beans:jar:sources:4.1.5.RELEASE:compile
			[INFO]
			[INFO] The following files have NOT been resolved:
			[INFO]    org.springframework:spring-context:jar:sources:4.1.5.RELEASE:compile
			[INFO]
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
dependency:tree  [ 项目依赖树 ]
mvn dependency:tree
		    F:\dev\share\myapp>mvn dependency:tree
			[INFO] org.lychie:myapp:jar:1.0
			[INFO] +- org.springframework:spring-core:jar:4.1.5.RELEASE:compile
			[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
			[INFO] +- org.springframework:spring-webmvc:jar:4.1.5.RELEASE:compile
			[INFO] |  +- org.springframework:spring-beans:jar:4.1.5.RELEASE:compile
			[INFO] |  +- org.springframework:spring-context:jar:4.1.5.RELEASE:compile
			[INFO] |  |  \- org.springframework:spring-aop:jar:4.1.5.RELEASE:compile
			[INFO] |  |     \- aopalliance:aopalliance:jar:1.0:compile
			[INFO] |  +- org.springframework:spring-expression:jar:4.1.5.RELEASE:compile
			[INFO] |  \- org.springframework:spring-web:jar:4.1.5.RELEASE:compile
			[INFO] \- junit:junit:jar:4.7:test
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
project-info-reports:dependencies  [ 项目依赖报告 ]
mvn project-info-reports:dependencies ( 见 target/site/dependencies.html )
		    F:\dev\share\myapp>mvn project-info-reports:dependencies
			[INFO] --- maven-project-info-reports-plugin:2.4:dependencies (default-cli) @ myapp ---
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
help:effective-pom  [ 查看有效的 pom 配置 ]
mvn help:effective-pom ( 暴露 super pom )
		    F:\dev\share\myapp>mvn help:effective-pom
		    
			
			
			
			
			
			
			<project>
			  . . . . . .
			  <properties>
			    <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
			    <maven.compiler.source>1.7</maven.compiler.source>
			    <maven.compiler.target>1.7</maven.compiler.target>
			    <spring.version>4.1.5.RELEASE</spring.version>
			  </properties>
			  <dependencies>
			    <dependency>
			      <groupId>org.springframework</groupId>
			      <artifactId>spring-core</artifactId>
			      <version>4.1.5.RELEASE</version>
			      <scope>compile</scope>
			    </dependency>
			    <dependency>
			      <groupId>org.springframework</groupId>
			      <artifactId>spring-webmvc</artifactId>
			      <version>4.1.5.RELEASE</version>
			      <scope>compile</scope>
			    </dependency>
			  </dependencies>
			  <repositories>
			    <repository>
			      <snapshots>
			        <enabled>false</enabled>
			      </snapshots>
			      <id>central</id>
			      <name>Central Repository</name>
			      <url>https://repo.maven.apache.org/maven2</url>
			    </repository>
			  </repositories>
			  <build>
			    <finalName>myapp-1.0</finalName>
			  </build>
			  . . . . . .
			</project>
			
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
help:describe  [ 获取插件帮助 ]
mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull
		    F:\dev\share\myapp>mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull
			[INFO] Mojo: 'compiler:compile'
			compiler:compile
			  Description: Compiles application sources
			  Implementation: org.apache.maven.plugin.compiler.CompilerMojo
			  Language: java
			  Bound to phase: compile
			
			  Available parameters:
			
			    debug (Default: true)
			      Expression: ${maven.compiler.debug}
			      Set to true to include debugging information in the compiled class files.
			
			    encoding (Default: ${project.build.sourceEncoding})
			      Expression: ${encoding}
			      The -encoding argument for the Java compiler.
			. . . . . .
			
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
dependency:resolve  [ 已解决的依赖列表 ]
mvn dependency:resolve
		    F:\dev\share\myapp>mvn dependency:resolve
			[INFO] The following files have been resolved:
			[INFO]    org.springframework:spring-aop:jar:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-beans:jar:4.1.5.RELEASE:compile
			[INFO]    commons-logging:commons-logging:jar:1.2:compile
			[INFO]    aopalliance:aopalliance:jar:1.0:compile
			[INFO]    junit:junit:jar:4.7:test
			[INFO]    org.springframework:spring-context:jar:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-core:jar:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-web:jar:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-webmvc:jar:4.1.5.RELEASE:compile
			[INFO]    org.springframework:spring-expression:jar:4.1.5.RELEASE:compile
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
idea:idea  [ 转换成 idea 项目 ]
mvn idea:idea
		    F:\dev\share\myapp>mvn idea:idea
			[INFO] >>> maven-idea-plugin:2.2.1:idea (default-cli) > generate-resources @ myapp >>>
			[INFO]
			[INFO] <<< maven-idea-plugin:2.2.1:idea (default-cli) < generate-resources @ myapp <<<
			[INFO]
			[INFO] --- maven-idea-plugin:2.2.1:idea (default-cli) @ myapp ---
			[INFO] jdkName is not set, using [java version1.7.0_75] as default.
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
eclipse:eclipse  [ 转换成 eclipse 项目 ]
mvn eclipse:eclipse
		    F:\dev\share\myapp>mvn eclipse:eclipse
			[INFO] >>> maven-eclipse-plugin:2.9:eclipse (default-cli) > generate-resources @ myapp >>>
			[INFO]
			[INFO] <<< maven-eclipse-plugin:2.9:eclipse (default-cli) < generate-resources @ myapp <<<
			[INFO]
			[INFO] --- maven-eclipse-plugin:2.9:eclipse (default-cli) @ myapp ---
			[INFO] Using Eclipse Workspace: null
			[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
			[INFO] Not writing settings - defaults suffice
			[INFO] Wrote Eclipse project for "myapp" to F:\dev\share\myapp.
			[INFO]
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
archetype:create  [ 创建 java 项目 ]
mvn archetype:create -DgroupId=org.lychie -DartifactId=myapp
		    F:\dev\share>mvn archetype:create -DgroupId=org.lychie -DartifactId=myapp
			[INFO] Parameter: groupId, Value: org.lychie
			[INFO] Parameter: packageName, Value: org.lychie
			[INFO] Parameter: package, Value: org.lychie
			[INFO] Parameter: artifactId, Value: myapp
			[INFO] Parameter: basedir, Value: F:\dev\share
			[INFO] Parameter: version, Value: 1.0-SNAPSHOT
			[INFO] project created from Old (1.x) Archetype in dir: F:\dev\share\myapp
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    
archetype:create  [ 创建 web 项目 ]
mvn archetype:create -DgroupId=org.lychie -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-webapp
		    F:\dev\share>mvn archetype:create -DgroupId=org.lychie -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-webapp
			[INFO] Parameter: groupId, Value: org.lychie
			[INFO] Parameter: packageName, Value: org.lychie
			[INFO] Parameter: package, Value: org.lychie
			[INFO] Parameter: artifactId, Value: myproject
			[INFO] Parameter: basedir, Value: F:\dev\share
			[INFO] Parameter: version, Value: 1.0-SNAPSHOT
			[INFO] project created from Old (1.x) Archetype in dir: F:\dev\share\myproject
			[INFO] ------------------------------------------------------------------------
			[INFO] BUILD SUCCESS
			[INFO] ------------------------------------------------------------------------
		    

示例代码下载
myapp.zip