maven上传源码到私服

上传源码

项目中采用了分模块的方式构建,直接将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 既可将源码上传到私服中

打包问题

封装过公共组件的同志们都知道,工具组件需要不断的维护升级,还好现在有maven来帮助我们管理各个版本的jar包,但是如何正确的使用maven来让团队使用我们jar呢,这就是我们接下来介绍的。

首先我们开发的版本都是 SNAPSHOT ,但是当被项目组使用的时候需要发布RELEASE版本来使用,这样不至于我们更改的代码影响团队的使用。因此在deploy项目的时候我们可以分为三部来操作

mvn versions:set -DnewVersion=1.0.0.RELEASE
mvn deploy
mvn versions:set -DnewVersion=0.0.1-SNAPSHOT

第一步:我们设置当前项目的版本号为 1.0.0Release,这是maven会自动将多模块中所有模块的版本号都更改为当前我们设置的

第二步:继续使用deploy上传代码

第三步:我们要继续开发自己的功能,所以需要将项目中的版本号更改为SNAPSHOT

上面的1.0.0 和 0.0.1 需要根据项目来定,没有固定的要求

 pom中配置配置Nexus

<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://x.x.x.x:port/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://x.x.x.x:port/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
posted @ 2018-11-07 18:50  mickey007  阅读(8664)  评论(0编辑  收藏  举报