Nexus搭建Maven私服

jdk

下载nexus仓库管理器

bash

wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/oss/nexus-2.14.8-01-bundle.tar.gz

解压

bash

tar -zxf nexus-2.14.3-02-bundle.tar.gz
mv nexus-2.14.3-02-bundle /usr/local/nexus

编辑配置文件

text

vi conf/nexus.properties

text

# Jetty section
application-port=8081   # 访问端口
application-host=0.0.0.0  # 绑定IP
nexus-webapp=${bundleBasedir}/nexus  # 指定nexus程序目录
nexus-webapp-context-path=/nexus   # 指定访问的二组目录

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

以上都是默认配置,对应的访问地址为:

http://x.x.x.x:8081/nexus

如果要改为http://x.x.x.x:8081,则修改nexus-webapp-context-path=/即可

启动脚本:

bash

bin/nexus start

启动脚本有如下参数可选

bash

bin/nexus
Usage: ./nexus { console | start | stop | restart | status | dump }

默认用户:

admin/admin123 deployment/deployment123

修改用户信息

admin登陆后,点击左侧【Security–Users】,在列表中选择用户,右键可更改密码和重围密码, 底部表格中可修改用户其余信息

点击左侧【Views/Repositories–Repositories】,选择【Public Repositories】,复制其Repository Path字段

编辑 pom.xml 文件,添加如下段:

xml

<!-- 设定主仓库,按设定顺序进行查找。 -->
<!-- 设定主仓库,按设定顺序进行查找。 -->
    <repositories>
        <repository>
            <id>releases</id>
            <name>Team Nexus Repository</name>
            <url>${Repository Path}</url>
        </repository>

        <repository>
            <id>snapshots</id>
            <name>Team Nexus Repository</name>
            <url>${Repository Path}</url>
        </repository>
</repositories>

点击左侧【Views/Repositories–Repositories】,选择【 Release 或 Snapshots】,复制其Repository Path字段

编辑pom.xml文件,添加如下段:

xml

<!-- 设定发布位置,mvn deploy时用到,不设置时会报错-->
    <distributionManagement>
        <repository>
            <id>ci-releases</id>
            <name>Gigold Nexus Repository</name>
            <url>http://ci-gitlab:8081/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>ci-snapshots</id>
            <name>Gigold Nexus Repository</name>
            <url>http://ci-gitlab:8081/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

相关内容