maven 上传jar 包含源码

上传源码

项目中采用了分模块的方式构建,直接将maven-source-plugin写到父pom中,尝试了很多次发现源码一直不能上传到私服中,纠结了很长时间才发现原来多模块项目和普通一个项目的配置是有区别的,需要在每个需要上传源码的子模块中都配置maven-source-plugin才可以上传,于是乎有了一下的代码

1,非多模块项目

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <version>3.0.1</version>
      <configuration>
         <attach>true</attach>
      </configuration>
      <executions>
         <execution>
            <phase>compile</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
      </executions>
  </plugin>
</plugins>

2,多模块项目

在父pom中增加

<pluginManagement>
   <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>3.0.1</version>
          <configuration>
             <attach>true</attach>
          </configuration>
             <executions>
                 <execution>
                     <phase>compile</phase>
                         <goals>
                            <goal>jar</goal>
                         </goals>
                 </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>

子项目中增加

 <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

然后使用:mvn deploy 既可将源码上传到私服中

更多推荐