使用 maven 自动将源码打包并发布

1、maven-source-plugin 访问地址

在 pom.xml 中添加 下面的 内容,可以 使用 maven 生成 jar 的同时 生成 sources 包

<plugin>
    <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-source-pluginartifactId> <version>3.0.0version>  <executions> <execution>  <phase>compilephase>  <goals> <goal>jar-no-forkgoal> 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,单独打包源码。

另一种写法


<plugin>
    <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-source-pluginartifactId> <executions> <execution> <id>attach-sourcesid> <goals> <goal>jargoal> 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.0modelVersion>
  4     <groupId>com.jtgroupId>
  5     <artifactId>rabbitMQartifactId>
  6     <version>1.0.0.RELEASEversion>
  7 
  8     <properties>
  9         <spring.version>4.1.3.RELEASEspring.version>
 10     properties>
 11 
 12     <dependencies>
 13         
 14         <dependency>
 15             <groupId>org.springframeworkgroupId>
 16             <artifactId>spring-contextartifactId>
 17             <version>${spring.version}version>
 18         dependency>
 19         <dependency>
 20             <groupId>org.springframeworkgroupId>
 21             <artifactId>spring-beansartifactId>
 22             <version>${spring.version}version>
 23         dependency>
 24         <dependency>
 25             <groupId>org.springframeworkgroupId>
 26             <artifactId>spring-webmvcartifactId>
 27             <version>${spring.version}version>
 28         dependency>
 29         <dependency>
 30             <groupId>org.springframeworkgroupId>
 31             <artifactId>spring-jdbcartifactId>
 32             <version>${spring.version}version>
 33         dependency>
 34         <dependency>
 35             <groupId>org.springframeworkgroupId>
 36             <artifactId>spring-aspectsartifactId>
 37             <version>${spring.version}version>
 38         dependency>
 39 
 40         <dependency>
 41             <groupId>com.rabbitmqgroupId>
 42             <artifactId>amqp-clientartifactId>
 43             <version>4.0.2version>
 44         dependency>
 45 
 46         <dependency>
 47             <groupId>org.slf4jgroupId>
 48             <artifactId>slf4j-apiartifactId>
 49             <version>1.7.10version>
 50         dependency>
 51 
 52         <dependency>
 53             <groupId>org.slf4jgroupId>
 54             <artifactId>slf4j-log4j12artifactId>
 55             <version>1.7.5version>
 56         dependency>
 57 
 58         <dependency>
 59             <groupId>log4jgroupId>
 60             <artifactId>log4jartifactId>
 61             <version>1.2.17version>
 62         dependency>
 63 
 64         <dependency>
 65             <groupId>junitgroupId>
 66             <artifactId>junitartifactId>
 67             <version>4.12version>
 68         dependency>
 69 
 70         <dependency>
 71             <groupId>org.springframework.amqpgroupId>
 72             <artifactId>spring-rabbitartifactId>
 73             <version>1.4.0.RELEASEversion>
 74         dependency>
 75     dependencies>
 76 
 77     <build>
 78         <plugins>
 79             <plugin>
 80                 <groupId>org.apache.maven.pluginsgroupId>
 81                 <artifactId>maven-compiler-pluginartifactId>
 82                 <version>3.1version>
 83                 <configuration>
 84                     <source>1.7source>
 85                     <target>1.7target>
 86                     <encoding>utf-8encoding>
 87                 configuration>
 88             plugin>
 89             
 90             <plugin>
 91                 <groupId>org.apache.maven.pluginsgroupId>
 92                 <artifactId>maven-surefire-pluginartifactId>
 93                 <version>2.18.1version>
 94                 <configuration>
 95                     <skip>trueskip>
 96                 configuration>
 97             plugin>
 98             
 99             <plugin>
100                 <groupId>org.apache.maven.pluginsgroupId>
101                 <artifactId>maven-source-pluginartifactId>
102                 <executions>
103                     <execution>
104                         <id>attach-sourcesid>
105                         <goals>
106                             <goal>jargoal>
107                         goals>
108                     execution>
109                 executions>
110             plugin>
111             <plugin>
112                 <groupId>org.apache.maven.pluginsgroupId>
113                 <artifactId>maven-source-pluginartifactId>
114                 <version>3.0.0version>
115                 
116                 <executions>
117                     <execution>
118                         
119                         <phase>compilephase>
120                         
121                         <goals>
122                             <goal>jar-no-forkgoal>
123                         goals>
124                     execution>
125                 executions>
126             plugin>
127 
128         plugins>
129     build>
130 project>

 

转载于:https://www.cnblogs.com/But-you/p/10537782.html

你可能感兴趣的:(java)