一、maven-source-plugin 訪問地址web
在 pom.xml 中添加 下面的 內容,能夠 使用 maven 生成 jar 的同時 生成 sources 包spring
<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,單獨打包源碼。apache
另外一種寫法api
<!-- 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中。markdown
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>