2019-05-08-idea+maven私服-配置nexus


name: 97年的顽石
avatar: /images/husky.png
home:
authorDesc: 一条咸鱼罢了
categories: 科技
tags:

  • nexus
    title: idea+maven私服-配置nexus
    date: 2019-05-08 12:50:34
    keywords:
    description: 暂无概述

mirror和repository的区别 概念在文章 → Maven:mirror和repository 区别 - bcombetter - 博客园(https://www.cnblogs.com/xingzc/p/9678984.html)


# 在项目中使用 Maven 私服**(Nexus)**

(使用时把aliyun配置在nexus里,pom.xml和setting.xml只留私服)

# 配置认证信息+镜像(Maven/conf/setting.xml)

(使用时把aliyun配置在nexus里,pom.xml和setting.xml只留私服)

效果就是Maven的所有请求必须经过镜像站点(Nexus);当Nexus出现问题后,那么Maven将强制不可用。

    <mirror>

        <id>mirror-redirect2nexus</id>

        <!-- 此处配置所有的构建均从私有仓库中下载,*代表所有,也可以写成central -->

        <!-- <mirrorOf>*</mirrorOf> -->

        <!-- <mirrorOf>nexus</mirrorOf> -->

        <mirrorOf>*</mirrorOf>

        <name>Nexus osc</name>

        <url>http://192.168.213.135:8081/repository/maven-public/</url>

    </mirror>



<server>

  <id>nexus-releases</id>

  <username>admin</username>

  <password>admin123</password>

</server>

<server>

  <id>nexus-snapshots</id>

  <username>admin</username>

  <password>admin123</password>

</server>

# Snapshots 与 Releases 的区别

  • nexus-releases: 用于发布 Release 版本
  • nexus-snapshots: 用于发布 Snapshot 版本(快照版)

Release 版本与 Snapshot 定义如下:

Release: 1.0.0/1.0.0-RELEASE

Snapshot: 1.0.0-SNAPSHOT

  • 在项目 pom.xml 中设置的版本号添加 SNAPSHOT 标识的都会发布为 SNAPSHOT 版本,没有 SNAPSHOT 标识的都会发布为 RELEASE 版本。
  • SNAPSHOT 版本会自动加一个时间作为标识,如:1.0.0-SNAPSHOT 发布后为变成 1.0.0-SNAPSHOT-20180522.123456-1.jar

# 配置自动化部署(IDEA pom.xml部分)

在(IDEA)pom.xml 中添加如下代码:

<distributionManagement>  

  <repository>  

    <id>nexus-releases</id>  

    <name>Nexus Release Repository</name>  

    <url>http://192.168.213.135:8081/repository/maven-releases/</url>  

  </repository>  

  <snapshotRepository>  

    <id>nexus-snapshots</id>  

    <name>Nexus Snapshot Repository</name>  

    <url>http://192.168.213.135:8081/repository/maven-snapshots/</url>  

  </snapshotRepository>  

</distributionManagement>

注意事项:

  • ID 名称必须要与 settings.xml 中 Servers 配置的 ID 名称保持一致。
  • 项目版本号中有 SNAPSHOT 标识的,会发布到 Nexus Snapshots Repository, 否则发布到 Nexus Release Repository,并根据 ID 去匹配授权账号。

# 部署到仓库

mvn deploy

# 上传第三方 JAR 包

Nexus 3.0 不支持页面上传,可使用 maven 命令:

# 如第三方JAR包:aliyun-sdk-oss-2.2.3.jar

mvn deploy:deploy-file

  -DgroupId=com.aliyun.oss

  -DartifactId=aliyun-sdk-oss

  -Dversion=2.2.3

  -Dpackaging=jar

  -Dfile=D:\aliyun-sdk-oss-2.2.3.jar

  -Durl=http://127.0.0.1:8081/repository/maven-3rd/

  -DrepositoryId=nexus-releases

注意事项:

  • 建议在上传第三方 JAR 包时,创建单独的第三方 JAR 包管理仓库,便于管理有维护。(maven-3rd)
  • -DrepositoryId=nexus-releases 对应的是 settings.xml 中 Servers 配置的 ID 名称。(授权)

# 配置代理仓库**(IDEA pom.xml部分)**

(使用时把aliyun配置在nexus里,pom.xml和setting.xml只留私服)

<repositories>

    <repository>

        <id>nexus</id>

        <name>Nexus Repository</name>

        <url>http://192.168.213.135:8081/repository/maven-public/</url>

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

        <releases>

            <enabled>true</enabled>

        </releases>

    </repository>

</repositories>

<pluginRepositories>

    <pluginRepository>

        <id>nexus</id>

        <name>Nexus Plugin Repository</name>

        <url>http://192.168.213.135:8081/repository/maven-public/</url>

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

        <releases>

            <enabled>true</enabled>

        </releases>

    </pluginRepository>

</pluginRepositories>


# Nexus添加阿里云仓库(http://192.168.213.135:8081 登陆并设置**):**

(使用时把aliyun配置在nexus里,pom.xml和setting.xml只留私服)

    把一下都配上,并设置maven-public 调整到 maven-release/public/centrol 之前.(范例在代码最下方)
setting.xml

    <mirror>

        <id>alimaven</id>

        <name>aliyun maven</name>

        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

        <mirrorOf>central</mirrorOf>

    </mirror>

    <mirror>

        <id>central</id>

        <name>Maven Repository Switchboard</name>

        <url>http://repo1.maven.org/maven2/</url>

        <mirrorOf>central</mirrorOf>

    </mirror>

    <mirror>

        <id>repo2</id>

        <mirrorOf>central</mirrorOf>

        <name>Human Readable Name for this Mirror.</name>

        <url>http://repo2.maven.org/maven2/</url>

    </mirror>

    <mirror>

        <id>ibiblio</id>

        <mirrorOf>central</mirrorOf>

        <name>Human Readable Name for this Mirror.</name>

        <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>

    </mirror>

    <mirror>

        <id>jboss-public-repository-group</id>

        <mirrorOf>central</mirrorOf>

        <name>JBoss Public Repository Group</name>

        <url>http://repository.jboss.org/nexus/content/groups/public</url>

    </mirror>

    <!-- 中央仓库在中国的镜像 -->

    <mirror>

        <id>maven.net.cn</id>

        <name>oneof the central mirrors in china</name>

        <url>http://maven.net.cn/content/groups/public/</url>

        <mirrorOf>central</mirrorOf>

    </mirror>



pom.xml

    <repositories>

        <repository>

            <id>aliyun-repos</id>

            <name>Aliyun Repository</name>

            <url>http://maven.aliyun.com/nexus/content/groups/public</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

        </repository>

    </repositories>

    <pluginRepositories>

        <pluginRepository>

            <id>aliyun-repos</id>

            <name>Aliyun Repository</name>

            <url>http://maven.aliyun.com/nexus/content/groups/public</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

        </pluginRepository>

    </pluginRepositories>

范例: 如下图,点击 Repositories → Create repository → maven2 proxy

取名: aliyun-repository

URL:http://maven.aliyun.com/nexus/content/groups/public/,其他默认值即可。

1
2 配置public-repository:
2
将aliyun的repository排到最上面,如下图:
3

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值