marven系列9-nexus快照版和发布版使用

配置仓库环境

nexus3新建snapshot和releases的宿主仓库并加入仓库组
《marven系列9-nexus快照版和发布版使用》

在配置文件setting中添加

 <server>
      <id>shadow_snapshot</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>shadow_releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

在pom.xml中添加nexus发布地址

<distributionManagement>
        <!-- 发布版地址 -->
        <repository>
            <id>shadow_releases</id>
            <url>http://144.202.91.42:8081/repository/shadow_releases/</url>
        </repository>
        <!-- 快照版地址 -->
        <snapshotRepository>
            <id>shadow_snapshot</id>
            <url>http://144.202.91.42:8081/repository/shadow_snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

用参数自动控制发布版本

maven会判断版本后面是否带了-SNAPSHOT,如果带了就发布到snapshots仓库,否则发布到release仓库。这里我们可以在pom.xml文件中

<groupId>com.wy</groupId>
<artifactId>nexus_test</artifactId>
<packaging>jar</packaging>
<version>${project.release.version}</version>

<properties>
    <project.release.version>1.0-SNAPSHOT</project.release.version>
</properties>

<profiles>
    <profile>
        <id>product</id>
        <properties>
            <project.release.version>1.0</project.release.version>
        </properties>
    </profile>
</profiles>

说明:通过占位符${project.release.version}来控制需要发布的版本,用命令mvn deploy -P product,发布my-test的1.0版本到releases库。如果使用命令mvn deploy,则默认使用 1.0-SNAPSHOT版本号,将发布my-test的1.0-SNAPSHOT版本到snapshots库。

测试

nexus_test项目的pom.xml配置如下

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wy</groupId>
  <artifactId>nexus_test</artifactId>
 <packaging>jar</packaging>
<version>${project.release.version}</version>

<properties>
    <project.release.version>1.0-SNAPSHOT</project.release.version>
    <project.build.sourceEncoding> UTF-8</project.build.sourceEncoding>
</properties>

  <build/>
  <profiles>
    <profile>
        <id>product</id>
        <properties>
            <project.release.version>1.0</project.release.version>
        </properties>
    </profile>
</profiles>

   <distributionManagement>
        <!-- 发布版地址 -->
        <repository>
            <id>shadow_releases</id>
            <url>http://144.202.91.42:8081/repository/shadow_releases/</url>
        </repository>
        <!-- 快照版地址 -->
        <snapshotRepository>
            <id>shadow_snapshot</id>
            <url>http://144.202.91.42:8081/repository/shadow_snapshot/</url>
        </snapshotRepository>
    </distributionManagement>
</project>

《marven系列9-nexus快照版和发布版使用》

《marven系列9-nexus快照版和发布版使用》

《marven系列9-nexus快照版和发布版使用》

《marven系列9-nexus快照版和发布版使用》

《marven系列9-nexus快照版和发布版使用》

《marven系列9-nexus快照版和发布版使用》

第三方jar包上传到nexus

mvn deploy:deploy-file -DgroupId=sxd.jar -DartifactId=jacob -Dversion=1.18 -Dpackaging=jar -Dfile=G:\jar\jacob-1.18.jar -Durl=http://144.202.91.42:8081/repository/shadow_releases/ -DrepositoryId=shadow_releases

命令解释:

-DgroupId=sxd.jar                           自定义

-DartifactId=jacob                          自定义

-Dversion=1.18                            自定义 三个自定义,构成pom.xml文件中的坐标

-Dpackaging=jar                           上传的类型是jar类型

-Dfile=G:\jar\jacob-1.18.jar                   jar的本地磁盘位置

-Durl=http://144.202.91.42:8081/repository/shadow_releases/    hosted资源库的地址,下图中

-DrepositoryId=shadow_releases 对应的就是Maven中settings.xml的认证配的名字。

点赞

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注