一、Maven仓库概要

私服的目的:我们有一些自己的公用包,不想拉取工程编译,直接使用已经上传到私服的Jar包,在需要使用的项目工程直接引用使用,加速开发效率和编译效率。

阿里云仓库地址

  • 公用主仓库:https://maven.aliyun.com/mvn/view
  • 私有仓库:https://repomanage.rdc.aliyun.com/my/repo

二、配置私有仓库

配置settings.xml

方式1:直接下载settings.xml

直接下载settings.xml文件,然后将该文件内容放置到USER_HOME/.m2/settings.xml中

方式2:手动配置settings.xml

1、在servers节点添加如下配置(基于安全考虑页面上不显示密码,点击右侧的复制按钮可以获取包含密码的配置)

<servers>
    <server>
        <id>rdc-releases</id>
        <username>8BiQdZ</username>
        <password>******</password>
    </server>
    <server>
        <id>rdc-snapshots</id>
        <username>8BiQdZ</username>
        <password>******</password>
    </server>
</servers>

2、在profiles节点添加如下配置

<profile>
     <id>rdc-private-repo</id>
     <repositories>
         <repository>
             <id>rdc-releases</id>
             <url>https://repo.rdc.aliyun.com/repository/741-release-****/</url>
         </repository>
     <repository>
         <id>rdc-snapshots</id>
         <url>https://repo.rdc.aliyun.com/repository/741-snapshot-****/</url>
         </repository>
     </repositories>
</profile>

制品上传配置

配置好了settings.xml后,在代码库根目录下的pom.xml加入以下配置

<distributionManagement>
     <repository>
         <id>rdc-releases</id>
         <url>https://repo.rdc.aliyun.com/repository/741-release-****/</url>
     </repository>
     <snapshotRepository>
         <id>rdc-snapshots</id>
         <url>https://repo.rdc.aliyun.com/repository/741-snapshot-****/</url>
     </snapshotRepository>
</distributionManagement>

然后运行以下命令即可将制品推送到私有仓库中

$ mvn clean deploy -DskipTests

三、在具体工程中使用

1、在模块工程中添加私服配置

2、对需要上传的工程打包

 

3、配置打包命令,上传到私服上

特别注意:

  • 1、如果打包工程项目中pom.xml文件中,版本号带有 SNAPSHOT,打包上传到SNAPSHOT仓库中

可以重复执行 `deploy` 部署到仓库中

  • 2、如果打包工程项目中pom.xml文件中,版本号不带有 SNAPSHOT,打包上传到RELEASE仓库中

不可以重复 `deploy` 部署到仓库中,如果需要覆盖,先到仓库中删除以前版本,或者在工程中修改版本号,再部署上传

  • SNAPSHOT 版本 

  • release 版本 

 

 

 

4、上传成功,查看

5、在其他项目工程中使用,在工程中加入引用,相关联的包已经关联进来

特别注意:保持包的版本一致性,以免引入的包冲突

 

 

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐