1、maven-source-plugin 访问地址
在 pom.xml 中添加 下面的 内容,可以 使用 maven 生成 jar 的同时 生成 sources 包
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal -->
<executions>
<execution>
<!-- 绑定source插件到Maven的生命周期 -->
<phase>compile</phase>
<!--在生命周期后执行绑定的source插件的goals -->
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
maven-source-plugin提供项目自动将源码打包并发布的功能,在需要发布源码项目的pom.xml文件中添加如下代码即可
执行 mvn install,maven会自动将source install到repository 。
执行 mvn deploy,maven会自动将source deploy到remote-repository 。
执行 mvn source:jar,单独打包源码。
另一种写法
<!-- Source attach plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
注意:在多项目构建中,将source-plugin置于顶层或parent的pom中并不会发挥作用,必须置于具体项目的pom中。
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.jt</groupId> 5 <artifactId>rabbitMQ</artifactId> 6 <version>1.0.0.RELEASE</version> 7 8 <properties> 9 <spring.version>4.1.3.RELEASE</spring.version> 10 </properties> 11 12 <dependencies> 13 <!-- Spring --> 14 <dependency> 15 <groupId>org.springframework</groupId> 16 <artifactId>spring-context</artifactId> 17 <version>${spring.version}</version> 18 </dependency> 19 <dependency> 20 <groupId>org.springframework</groupId> 21 <artifactId>spring-beans</artifactId> 22 <version>${spring.version}</version> 23 </dependency> 24 <dependency> 25 <groupId>org.springframework</groupId> 26 <artifactId>spring-webmvc</artifactId> 27 <version>${spring.version}</version> 28 </dependency> 29 <dependency> 30 <groupId>org.springframework</groupId> 31 <artifactId>spring-jdbc</artifactId> 32 <version>${spring.version}</version> 33 </dependency> 34 <dependency> 35 <groupId>org.springframework</groupId> 36 <artifactId>spring-aspects</artifactId> 37 <version>${spring.version}</version> 38 </dependency> 39 40 <dependency> 41 <groupId>com.rabbitmq</groupId> 42 <artifactId>amqp-client</artifactId> 43 <version>4.0.2</version> 44 </dependency> 45 46 <dependency> 47 <groupId>org.slf4j</groupId> 48 <artifactId>slf4j-api</artifactId> 49 <version>1.7.10</version> 50 </dependency> 51 52 <dependency> 53 <groupId>org.slf4j</groupId> 54 <artifactId>slf4j-log4j12</artifactId> 55 <version>1.7.5</version> 56 </dependency> 57 58 <dependency> 59 <groupId>log4j</groupId> 60 <artifactId>log4j</artifactId> 61 <version>1.2.17</version> 62 </dependency> 63 64 <dependency> 65 <groupId>junit</groupId> 66 <artifactId>junit</artifactId> 67 <version>4.12</version> 68 </dependency> 69 70 <dependency> 71 <groupId>org.springframework.amqp</groupId> 72 <artifactId>spring-rabbit</artifactId> 73 <version>1.4.0.RELEASE</version> 74 </dependency> 75 </dependencies> 76 77 <build> 78 <plugins> 79 <plugin> 80 <groupId>org.apache.maven.plugins</groupId> 81 <artifactId>maven-compiler-plugin</artifactId> 82 <version>3.1</version> 83 <configuration> 84 <source>1.7</source> 85 <target>1.7</target> 86 <encoding>utf-8</encoding> 87 </configuration> 88 </plugin> 89 <!-- 打包的时候跳过测试junit begin --> 90 <plugin> 91 <groupId>org.apache.maven.plugins</groupId> 92 <artifactId>maven-surefire-plugin</artifactId> 93 <version>2.18.1</version> 94 <configuration> 95 <skip>true</skip> 96 </configuration> 97 </plugin> 98 <!-- Source attach plugin --> 99 <plugin> 100 <groupId>org.apache.maven.plugins</groupId> 101 <artifactId>maven-source-plugin</artifactId> 102 <executions> 103 <execution> 104 <id>attach-sources</id> 105 <goals> 106 <goal>jar</goal> 107 </goals> 108 </execution> 109 </executions> 110 </plugin> 111 <plugin> 112 <groupId>org.apache.maven.plugins</groupId> 113 <artifactId>maven-source-plugin</artifactId> 114 <version>3.0.0</version> 115 <!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal --> 116 <executions> 117 <execution> 118 <!-- 绑定source插件到Maven的生命周期 --> 119 <phase>compile</phase> 120 <!--在生命周期后执行绑定的source插件的goals --> 121 <goals> 122 <goal>jar-no-fork</goal> 123 </goals> 124 </execution> 125 </executions> 126 </plugin> 127 128 </plugins> 129 </build> 130 </project>