标签:des style blog http color io os ar for
一 、打包同时生成源码 maven-source-plugin
1 <plugin> 2 <artifactId>maven-source-plugin</artifactId> 3 <version>2.4</version> 4 <executions> 5 <execution> 6 <phase>package</phase> 7 <goals> 8 <goal>jar-no-fork</goal> 9 </goals> 10 </execution> 11 </executions> 12 </plugin>
二、 打包时跳过单元测试 maven-surefire-plugin
1 <plugin> 2 <artifactId>maven-surefire-plugin</artifactId> 3 <version>2.6</version> 4 <configuration> 5 <skip>true</skip> 6 </configuration> 7 </plugin>
注:起作用的是<skip>true</skip>,改成false后,单元测试就会被执行
三、 单独打包依赖项 maven-assembly-plugin
1 <plugin> 2 <artifactId>maven-assembly-plugin</artifactId> 3 <version>2.4.1</version> 4 <configuration> 5 <finalName>mylib</finalName> 6 <appendAssemblyId>false</appendAssemblyId> 7 <encoding>utf-8</encoding> 8 <descriptors> 9 <descriptor>src/main/assembly/src.xml</descriptor> 10 </descriptors> 11 <descriptorRefs> 12 <descriptorRef>jar-with-dependencies</descriptorRef> 13 </descriptorRefs> 14 </configuration> 15 <executions> 16 <execution> 17 <id>make-assembly</id> 18 <phase>package</phase> 19 <goals> 20 <goal>single</goal> 21 </goals> 22 </execution> 23 </executions> 24 </plugin>
注:<descriptor>src/main/assembly/src.xml</descriptor> 这里需要在src/main/assembly下放一个src.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd"> 4 <id>package</id> 5 <formats> 6 <format>war</format> 7 </formats> 8 <includeBaseDirectory>false</includeBaseDirectory> 9 <!-- <fileSets> 10 <fileSet> 11 <directory>src/main/bin</directory> 12 <outputDirectory>/</outputDirectory> 13 </fileSet> 14 <fileSet> 15 <directory>src/main/config</directory> 16 <outputDirectory>config</outputDirectory> 17 </fileSet> 18 </fileSets> --> 19 <dependencySets> 20 <dependencySet> 21 <outputDirectory>lib</outputDirectory> 22 <scope>runtime</scope> 23 </dependencySet> 24 </dependencySets> 25 </assembly>
最终所有依赖项,会生成一个名为mylib.war的独立文件(文件名是由<finalName>...</finalName>节点决定的)
另:
<descriptors>
<descriptor>src/main/assembly/src.xml</descriptor>
</descriptors>
这里<descriptor>...</descriptor>可重复出现,即可出现多个. 这也意味着,你同时可以有多个打包配置规则,比如依赖项打包成文件A,所有配置打包成文件B...
maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/yjmyzz/p/4034502.html