【maven详解-插件】maven插件学习之maven-source-plugin

在pom.xml文件build节点下加入以下代码:

 1 <plugin>  
 2         <groupId>org.apache.maven.plugins</groupId>  
 3         <artifactId>maven-source-plugin</artifactId>  
 4         <version>2.1.1</version>  
 5         <executions>  
 6             <execution>  
 7                 <id>attach-sources</id>  
 8                 <phase>package</phase>
 9                 <goals>  
10                     <goal>jar-no-fork</goal>  
11                 </goals>  
12             </execution>  
13         </executions>  
14 </plugin> 

用户可以根据需要将任何插件目标绑定到任何生命周期的阶段,如:将maven-source-plugin的jar-no-fork目标绑定到default生命周期的package阶段,这样,以后在执行mvn package命令打包项目时,在package阶段之后会执行源代码打包

execution下可配置phase属性, 意思是在什么阶段打包源文件。如<phase>install</phase>:在执行mvn install时打包源代码

DOS执行mvn install生成source.jar

 1 [INFO] ------------------------------------------------------------------------
 2 [INFO] Building common-base 0.0.1
 3 [INFO] ------------------------------------------------------------------------
 4 Downloading: http://121.41.105.153:8081/nexus/content/groups/public/org/apache/m
 5 aven/plugins/maven-source-plugin/maven-metadata.xml
 6 Downloaded: http://121.41.105.153:8081/nexus/content/groups/public/org/apache/ma
 7 ven/plugins/maven-source-plugin/maven-metadata.xml (746 B at 5.6 KB/sec)
 8 Downloading: http://121.41.105.153:8081/nexus/content/groups/public/org/codehaus
 9 /mojo/cobertura-maven-plugin/maven-metadata.xml
10 Downloaded: http://121.41.105.153:8081/nexus/content/groups/public/org/codehaus/
11 mojo/cobertura-maven-plugin/maven-metadata.xml (605 B at 4.7 KB/sec)
12 Downloading: http://121.41.105.153:8081/nexus/content/groups/public/org/apache/m
13 aven/plugins/maven-help-plugin/maven-metadata.xml
14 Downloaded: http://121.41.105.153:8081/nexus/content/groups/public/org/apache/ma
15 ven/plugins/maven-help-plugin/maven-metadata.xml (493 B at 3.7 KB/sec)
16 [INFO]
17 [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ common-b
18 ase ---
19 [INFO] Using 'UTF-8' encoding to copy filtered resources.
20 [INFO] Copying 6 resources
21 [INFO]
22 [INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ common-base -
23 --
24 [INFO] Compiling 180 source files to E:\cncrowd_workspace\common-deploy\common-b
25 ase\target\classes
26 [INFO]
27 [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @
28 common-base ---
29 [INFO] Using 'UTF-8' encoding to copy filtered resources.
30 [INFO] Copying 2 resources
31 [INFO]
32 [INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ commo
33 n-base ---
34 [INFO] Nothing to compile - all classes are up to date
35 [INFO]
36 [INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ common-base ---
37 [INFO] Surefire report directory: E:\cncrowd_workspace\common-deploy\common-base
38 \target\surefire-reports
39 There are no tests to run.
40 [INFO]
41 [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ common-base ---
42 [INFO] Building jar: E:\cncrowd_workspace\common-deploy\common-base\target\commo
43 n-base-0.0.1.jar
44 [INFO]
45 [INFO] >>> maven-source-plugin:2.4:jar (attach-sources) @ common-base >>>
46 [INFO]
47 [INFO] <<< maven-source-plugin:2.4:jar (attach-sources) @ common-base <<<
48 [INFO]
49 [INFO] --- maven-source-plugin:2.4:jar (attach-sources) @ common-base ---
50 [INFO] Building jar: E:\cncrowd_workspace\common-deploy\common-base\target\commo
51 n-base-0.0.1-sources.jar
52 [INFO]
53 [INFO] --- maven-install-plugin:2.5.1:install (default-install) @ common-base --
54 -
55 [INFO] Installing E:\cncrowd_workspace\common-deploy\common-base\target\common-b
56 ase-0.0.1.jar to D:\Maven\repository\com\common\item\base\common-base\0.0.1\comm
57 on-base-0.0.1.jar
58 [INFO] Installing E:\cncrowd_workspace\common-deploy\common-base\pom.xml to D:\M
59 aven\repository\com\common\item\base\common-base\0.0.1\common-base-0.0.1.pom
60 [INFO] Installing E:\cncrowd_workspace\common-deploy\common-base\target\common-b
61 ase-0.0.1-sources.jar to D:\Maven\repository\com\common\item\base\common-base\0.
62 0.1\common-base-0.0.1-sources.jar

执行结果:

补充:

执行 mvn install,maven会自动将source install到repository 。

执行 mvn deploy,maven会自动将source deploy到remote-repository 。

执行 mvn source:jar,单独打包源码。

手动安装MAVEN安装source代码到本地库:

mvn install:install-file -Dfile=E:/common-base-0.0.1-sources.jar -DgroupId=net.spy -DartifactId=spymemcached -Dversion=2.10.3 -Dpackaging=jar -Dclassifier=sources

 

转载于:https://www.cnblogs.com/yantz/p/4463374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven插件是一种可插拔的工具,可以在Maven构建过程中执行特定的任务。其中,maven-dependency-pluginmaven-surefire-plugin是两个常用的插件maven-dependency-plugin插件可以用来管理项目依赖,可以帮助我们列出项目中的依赖关系,复制依赖文件到指定目录,解压依赖文件等。常用的配置包括: - list:列出项目依赖 - copy-dependencies:将所有依赖文件复制到指定目录 - unpack:解压指定的依赖文件 maven-surefire-plugin插件则是用来执行项目的单元测试的。它可以在Maven构建过程中自动执行单元测试,并生成测试报告。常用的配置包括: - includes/excludes:指定要执行的测试类或排除的测试类 - parallel:指定测试是否并行执行 - reportsDirectory:指定测试报告生成的目录 在POM文件中配置这两个插件,可以通过以下方式: ``` <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> <configuration> <includes> <include>**/*Test.java</include> </includes> <parallel>methods</parallel> <threadCount>10</threadCount> <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> </configuration> </plugin> </plugins> </build> ``` 以上是一个简单的POM文件中Maven插件配置maven-dependency-pluginmaven-surefire-plugin的示例,其中maven-dependency-plugin在package阶段执行复制依赖文件的任务,maven-surefire-plugin在test阶段执行单元测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值