从mvn test的输出开始说起
当我们在user-core中执行mvn test时,执行的输出如下:
/software/devsoftware/jdk1.7.0_55/bin/java -Dmaven.home=/software/devsoftware/apache-maven-3.2.1 -Dclassworlds.conf=/software/devsoftware/apache-maven-3.2.1/bin/m2.conf -Didea.launcher.port=7532 -Didea.launcher.bin.path=/software/devsoftware/idea-IU-135.690/bin -Dfile.encoding=UTF-8 -classpath /software/devsoftware/apache-maven-3.2.1/boot/plexus-classworlds-2.5.1.jar:/software/devsoftware/idea-IU-135.690/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.2 test [INFO] Scanning for projects... [INFO] [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building user.core 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ user.core --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ user.core --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ user.core --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory ~/development/learnmaven/user.manager/user.core/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ user.core --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ user.core --- [INFO] Surefire report directory: ~/development/learnmaven/user.manager/user.core/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running HelloTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.08 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.501 s [INFO] Finished at: 2014-08-03T17:51:33+08:00 [INFO] Final Memory: 9M/104M [INFO] ----------------------------------------------------------------------
从执行结果中,我们可以看到,mvn test实际执行了如下几步包括src/main/resources下资源文件的编译,src/main/java下Java文件的编译,src/test/resources下资源文件的编译,src/test/java下Java文件的编译,以及最后运行测试。这五个步骤实际上是执行了三个插件的五个目标,mvn test的五个目标以及它们的次序是由Maven的生命周期控制的
maven-resources-plugin:2.6:resources
maven-compiler-plugin:2.5.1:compile
maven-resources-plugin:2.6:testResources
maven-compiler-plugin:2.5.1:testCompile
maven-surefire-plugin:2.12.4:test
Maven的三组生命周期
Maven定义了3组生命周期,
1. clean生命周期
2. default生命周期(也称为compile生命周期)
3. site生命周期
这些生命周期管理着我们在执行Maven的某个生命周期类的操作时,Maven到底做了什么事情,比如执行mvn clean,执行mvn compile,mvn test,mvn package,mvn install时,Maven执行build的过程。
参考:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
clean生命周期
pre-clean | executes processes needed prior to the actual project cleaning |
clean | remove all files generated by the previous build |
post-clean | executes processes needed to finalize the project cleaning |
Default生命周期
validate | validate the project is correct and all necessary information is available. |
initialize | initialize build state, e.g. set properties or create directories. |
generate-sources | generate any source code for inclusion in compilation. |
process-sources | process the source code, for example to filter any values. |
generate-resources | generate resources for inclusion in the package. |
process-resources | copy and process the resources into the destination directory, ready for packaging. |
compile | compile the source code of the project. |
process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
generate-test-sources | generate any test source code for inclusion in compilation. |
process-test-sources | process the test source code, for example to filter any values. |
generate-test-resources | create resources for testing. |
process-test-resources | copy and process the resources into the test destination directory. |
test-compile | compile the test source code into the test destination directory |
process-test-classes | post-process the generated files from test compilation, for example to do bytecode enhancement on Java classes. For Maven 2.0.5 and above. |
test | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
prepare-package | perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. (Maven 2.1 and above) |
package | take the compiled code and package it in its distributable format, such as a JAR. |
pre-integration-test | perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
post-integration-test | perform actions required after integration tests have been executed. This may including cleaning up the environment. |
verify | run any checks to verify the package is valid and meets quality criteria. |
install | install the package into the local repository, for use as a dependency in other projects locally. |
deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
上面的表格定义了当执行validate,compile,test,package,verify,install,deploy等目标时,这个目标包含哪些要执行的目标以及这些目标的执行顺序。这些目标由Maven的插件执行的,因此可以说,Maven的生命周期是可以通过添加插件机制来进行扩展和定制
执行compile目标时,是否会执行clean目标
因为compile目标属于Default生命周期,clean目标属于Clean生命周期,Default和Clean两个生命周期独立,因此,compile目标执行时,不会执行clean,因此,我们在Inteillj Idea中在Maven模块中执行compile时,不会触发clean操作
相关推荐
maven学习笔记maven学习笔记maven学习笔记
maven学习笔记,包含maven插件,maven的安装,中央仓库,自定义本地仓库等安装方法。
maven学习笔记,里面有maven的学习路线图,以及maven的核心知识
maven学习笔记整理
Maven 学习笔记
Maven的安装: (首先保证JDK版本在1.6以上) 1: 通过配置MAVEN_HOME 和 %% %MAVEN_HOME%\bin 然后进行mvn -version 测试 掌握 -Xms 与 -Xmx的相关配置 2: Maven目录分析: 2.1: bin: 含有mvn运行的脚本 2.2...
maven学习笔记,传智博客的两天maven培训课件,简单易懂,有项目代做,快速上手maven,欢迎大家下载。
从零开始学maven,maven学习笔记
Maven3实战笔记04——Maven的生命周期和插件。
NULL 博文链接:https://chengtong-java.iteye.com/blog/2174839
Maven学习笔记
Maven 教程:基础篇——尚硅谷学习笔记 2022年
Maven提供了开发人员构建项目的一个完整的生命周期框架。开发团队可以自动完成项目的基础工具建设,Maven使用标准的目录结构和默认生命周期。 在多个开发团队环境时,Maven可以设置按标准在非常短的时间里完成配置...
内容概要:maven学习笔记,适合刚接触maven的人能让你快速入门。 适用人群:大学生或者初基础maven的人 使用场景及目标:idea集成maven,用来下载依赖包
Maven学习笔记,使用中遇到的问题,集成eclipse的各种坑,以便记录,为了以后复习使用。
主要上传自己在学习mybatis、maven等知识点做的相关笔记,供大家一起学习研究
Maven学习笔记,为个人在网上学习搜集和总结的文档