使用deploy命令发布jar到私服仓库nexus

参考:https://www.cnblogs.com/chenhao0302/p/7793980.html

 

使用deploy命令部署jar到私服仓库nexus
一 配置settings.xml(前提在nexus中创建好账号密码)
因为nexus是需要登陆操作,这里配置的是具有发布权限的账号,其中id要与pom文件中的id一致。
在settings.xml的<servers>里配置:

  <servers>
    <server>
      <id>nexus-releases</id>
      <username>nexus-releases</username>
      <password>123456</password>
    </server>
	<server>
      <id>nexus-snapshots</id>
      <username>nexus-snapshots</username>
      <password>123456</password>
    </server>
  </servers>

二、配置项目的pom.xml文件
其中id要与settings.xm文件中的id一致。

    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <url>http://xxxx:8081/repository/maven-public/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>http://xxxx:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

如果在<build>标签里添加以下配置,将在发布时将XXX-source.jar的源码同时部署到仓库
 

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

三、
运行 mvn deploy -DskipTests将项目部署到私服,部署并跳过测试

 

其它:
四、批量修改版本号
方式一: 在根module执行 mvn- versions:set -DnewVersion=XXX 
方式二:更新了根module的版本号后执行 mvn -N versions:update-child-modules


五、用cmd执行(win10的powershell可能会执行失败)
// 该方式是手动发布jar到仓库,不会发布source-jar
mvn deploy:deploy-file -DgroupId=net.xx.hello -DartifactId=xx-hello-Dversion=1.0.2-SNAPSHOT -Dpackaging=jar -Dfile=my-config-spring-1.0.2-SNAPSHOT.jar -DrepositoryId=Snapshots -Durl=http://repos.XXX.com:6060/nexus/content/repositories/snapshots/

其中:
-DgroupId -DartifactId -Dversion 是包在maven仓库的座标地址,
-Dpackaging 指名包的类型 pom、jar、other
-Dfile 指明包的名字,可以是绝对路径,也可以是相对路径
-DrepositoryId 指明需上传到目标仓库的ID号
-Durl 指名需要上传到目标仓库的URL地址

 六、注意事项

发布子module的时候,父pom要同步发布

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章