maven学习第一阶段

核心插件

一 、

maven-clean-pluginclean : 删除build项目时产生的目录文件;默认情况删除在 project.build.directory, project.build.outputDirectory, project.build.testOutputDirectory, and project.reporting.outputDirectory.配置的目录。特殊的,只有一个goal : mvn clean:clean (第一个clean为插件名称,第二个为goal) 或 mvn clean pom中配置亦可以

二、

maven-compiler-plugincompiler:编译项目的源代码,从3.0开始,默认的编译器javax.tools.JavaCompiler(jdk1.6); 如果要使用javac强制使用插件,则必须配置插件选项forceJavacCompilerUse。 注意:默认source源与target目标是1.6
1.
2. org.apache.maven.plugins
3. maven-compiler-plugin
4. 3.8.1
5.
6. 1.8
7. 1.8
8. true </ verbose>
9. true</ fork>
10. <!-到javac的路径-> </ executable>
11. 1.3 </ compilerVersion>
12. 128m </ meminitial>
13. 512m </ maxmem>
14.
15.

有两个goal(两者已经绑定到maven生命周期内的适当阶段,在各自阶段中自动执行)editor:compiler 绑定到编译阶段,用于编译主要源文件; mvn compilereditor:testCompiler 绑定到测试编译阶段,用于编译测试源文件。 mvn test-compiler

三、

maven-deploy-plugindeploy:部署阶段(存储库的信息–位置,传输方法以及可选的用户账号 ;工件的信息–组,工件,版本,包装,分类器 ;部署者–一种实际执行部署的方法)------->pom/命令行/解析settings.xml有两目标:deploy 自动安装工件deploy-file 指定pom文件获取 部署方式例子: 通过内部ssh部署:
1.
2.
3. ssh-repository
4. scpexe://repository.mycompany.com/repository
5.
6.
7.
8.
9.
10.
11.
12. org.apache.maven.wagon
13. wagon-ssh-external
14. 1.0-beta-6
15.
16.
17.

通过FTP部署:        
1. <distributionManagement>
2. <repository>
3. <id>ftp-repository</id>
4. <url>ftp://repository.mycompany.com/repository</url>
5. </repository>
6. </distributionManagement>
7.  
8. <build>
9. <extensions>
10. <!-- Enabling the use of FTP -->
11. <extension>
12. <groupId>org.apache.maven.wagon</groupId>
13. <artifactId>wagon-ftp</artifactId>
14. <version>1.0-beta-6</version>
15. </extension>
16. </extensions>
17. </build>

四、

maven-failsafe-plugin (默认会生成report文件 txt/xml 在target/failsafe-report/TEST-*.xml)failsafe 用于集成测试;(与之相似的 maven-surefire-plugin用于单元测试–surefire某个test失败则build会立即stop),failsafe有安全机制,一直到verify阶段。集成测试在maven生命周期中有4个阶段: pre-integration-test 对运行的集成测试环境进行设置 integration-test 运行集成测试 post-integration-test 销毁集成测试环境 verify 验证集成测试的结果有两goalintegration-test 运行集成测试 mvn integration-testverify 验证结果是否通过 mvn verify
1.
2. org.apache.maven.plugins
3. maven-failsafe-plugin
4. 3.0.0-M4
5.
6.
7.
8. integration-test
9. verify
10.
11.
12.
13.

使用jetty与maven-failsafe-plugin : 方式:bind one of jetty:start, jetty:run, jetty:run-exploded or jetty:run-war to the pre-integration-test phase with daemonset to true, bind failsafe:integration-test to the integration-test phase, bind jetty:stop to the post-integration-test phase and finally bind failsafe:verify to the verify phase.
1.
2. org.apache.maven.plugins
3. maven-failsafe-plugin
4. 3.0.0-M4
5.
6.
7. integration-test
8.
9. integration-test
10.
11.
12.
13. verify
14.
15. verify
16.
17.
18.
19.
20.
21. org.eclipse.jetty
22. jetty-maven-plugin
23. 9.2.2.v20140723
24. […]
25.
26. […]
27. 10
28. 8005
29. STOP
30. […]
31.
32. […]
33.
34. […]
35.
36. start-jetty
37. pre-integration-test
38.
39. start
40.
41.
42. 0
43. true
44.
45.
46.
47. stop-jetty
48. post-integration-test
49.
50. stop
51.
52.
53. […]
54.
55. […]
56.

在测试开发期间,新加一个jetty实例—>方式:为了刷新之前所有正在运行的jetty实例,将jetty:stop绑定到jetty:run之前的预集成测试阶段pre-integration-test。
1.
2. org.eclipse.jetty
3. jetty-maven-plugin
4. 9.2.2.v20140723
5. […]
6.
7. […]
8.
9. start-jetty
10. pre-integration-test
11.
12.
13. stop
14. start
15.
16. […]
17.
18. […]
19.
20. […]
21.

五、

maven-install-plugininstall 默认build后存储目录为 ~/.m2/settings.xml的元素有3个goalinstall:install 自动安装install:install-file 可选的指定pom文件/也可以命令行参数install:help 显示install插件的帮助信息mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=path-to-your-artifact-jar -DpomFile=path-to-pom
1. mvn install:install-file -Dfile=your-artifact-1.0.jar
2. [-DpomFile=your-pom.xml]
3. [-Dsources=src.jar]
4. [-Djavadoc=apidocs.jar]
5. [-DgroupId=org.some.group]
6. [-DartifactId=your-artifact]
7. [-Dversion=1.0]
8. [-Dpackaging=jar]
9. [-Dclassifier=sources]
10. [-DgeneratePom=true]
11. [-DcreateChecksum=true]

六、

maven-resources-pluginresource 用于复制项目的资源到 输出目录(main资源/test资源)有3个goalresources:resources 复制main资源到main输出目录,默认自动执行,绑定在process-sources生命周期阶段。resources:testresources 复制test资源到test输出目录,默认自动执行,绑定在process-test-sources生命周期阶段。resources:copy-resources 自己配置指定的复制资源的输出目录;
1.
2.
3. …
4.
5. org.apache.maven.plugins
6. maven-resources-plugin
7. 3.1.0
8.
9. …
10. UTF-8
11. …
12.
13.
14.
15.
16.
17.
18. src/my-resources
19. true 作用看实例吧,命令行也可使用
20.
21. /*.txt
22.
23.
24. /test.*
25.
26.
27. …
28.
29. …
30.

七、

maven-site-pluginsite 用于生成项目的site (包含项目在pom中配置好的report)有7个goalsite:site 用于为单个项目生成站点;多模块会有问题,之间链接会无效。 site:deploy 用于使用Wagon支持的协议将生成的站点部署到POM的中指定的站点URL。 site:run 启动站点,按要求呈现文档以加快编辑速度。它使用Jetty作为web服务器。 site:stage 根据POM的部分中指定的站点URL,在本地暂存目录或模拟目录中生成站点。它可以用来测试多模块构建工作中模块站点之间的链接。此目标要求站点已经使用站点目标生成,例如通过调用mvn site。 site:stage-deploy 将生成的站点部署到staging或mock目录,并部署到POM的部分中指定的站点URL。 site:stage-desriptor 新增site描述 site:jar 将站点输出打包到JAR中,以便将其部署到存储库中 site:effective-site 在继承之前描述和插入新的描述后,计算出有效的描述
1.
2.
3. www.yourcompany.com
4. scp://www.yourcompany.com/www/docs/project/
5.
6.

1. mvn site:stage-deploy -DstagingSiteURL=scp://www.mycompany.com/www/project/

八、

maven-surefire-plugin有一个goalsurefire:test mvn test 运行单元测试

九、

maven-verifier-pluginverifier 验证文件/目录是否存在,并根据正则表达式选择检查文件内容。一个goalverifier:verifier 若要在生成期间验证文件系统资源,请在pom.xml中的“生成”部分下添加验证程序插件。您还需要创建包含验证规则的verifications.xml文件。将该文件的路径添加到verificationFile配置元素。org.apache.maven.pluginsmaven-verifier-plugin1.1src/test/verifier/verifications-test.xmlmainverifyverify verifications.xml
* checks that the file src/main/resources/file1.txt is present.
* checks that the file src/main/resources/file2.txt is present and matches the regular expression aaaabbbb.
* checks that the file src/main/resources/file3.txt is not present.

<verifications xmlns="http://maven.apache.org/verifications/1.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=“http://maven.apache.org/verifications/1.0.0 http://maven.apache.org/xsd/verifications-1.0.0.xsd”>
src/main/resources/file1.txtsrc/main/resources/file2.txtaaaabbbbsrc/main/resources/file3.txtfalse

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值