nexus搭建流程

admin 发布时间:2022-07-15 分类:记事 阅读:1478次 添加评论

# Create repository。

创建的时候有type类型,proxy/hosted/group.

项目具体说明
hosted本地存储。像官方仓库一样提供本地私库功能
proxy提供代理其它仓库的类型
group组类型,能够组合多个仓库为一个地址提供服务

正常情况需要搭建两个repository,一个是hosted类型以便公司/团队内上传自己的包,一个是groups类型组合阿里以及自己团队的发布的包的一个集合repository。

groups类型的仓库需要包含hosted的仓,以便其他项目能够正常拉取;


# 配置1

创建2个仓库以后,修改自己的电脑上的maven配置,默认的settings.xml的文件位置在 C盘用户文件夹下的 .m2 文件中。 

如果需要发布上传内部的jar包则需要配置nexus账户及密码。

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>D://apache-maven-3.6.0-bin//localRestory</localRepository>   
    <servers>
        <server>
          <id>chow-commons</id>
          <username>admin</username>
          <password>123456</password>
        </server>
    </servers>
   <mirrors>
        <mirror>
            <id>chow-groups</id>
            <mirrorOf>central</mirrorOf>
            <name>中央仓库</name>
            <url>http://172.16.2.200/repository/chow-groups/</url>
        </mirror>
        <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
    
        <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
        </mirror>
    
        <!-- 中央仓库2 -->
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
    </mirrors> 
</settings>


# 项目上传jar公用包的配置

<distributionManagement>
    <repository>
        <id>chow-commons</id>
        <name>chow-nexus</name>
        <url>http://172.16.2.200:8081/repository/chow-commons/</url>
    </repository>
</distributionManagement>

然后在maven里,点击deploy或者执行命令:mvn deploy

# 项目引用公用包的配置

<dependency>
    <groupId>com.chow.commons</groupId>
    <artifactId>chow-entities</artifactId>
    <version>1.0-20220715.061559-2</version>
</dependency>


# 错误

出现错误:maven Transfer failed for jar 405 PUT,原因:上传的包对应仓库类型需要是hosted。

出现错误:Transfer failed for http://**********/maven-metadata.xml 503 Repository offline,原因:仓库配置了离线,设置库的Online勾选;


暂无留言

发表评论:

◎欢迎您的参与讨论。