美文网首页
nexus搭建maven私服

nexus搭建maven私服

作者: 给代码点颜色 | 来源:发表于2020-12-17 17:53 被阅读0次

简介

文档分为三部分,第一部分是私服环境搭建及配置启动过程,第二部分是私服的代理仓库等信息配置,第三部分是使用。

一、环境搭建步骤

1. 环境准备

下载安装jdk

这里使用的maven私服工具为nexus,依赖jdk环境。

下载JDK1.8,安装配置环境变量,这里就不赘述了。

下载安装nexus

地址:https://www.sonatype.com/nexus/repository-oss/download

不翻墙,你懂的

我下的版本是:nexus-3.13.0-01-unix.tar.gz

安装
  1. 创建文件夹nexus,并将压缩包拷到此目录下
  2. 解压nexus-3.13.0-01-unix.tar.gz(tar -zxvf nexus-3.13.0-01-unix/tar.gz

2. 启动配置

配置

配置内存参数

vim ./nexus-3.13.0-01/bin/nexus.vmoptions

image.png

按自己需求配置即可

配置端口、IP和路径(nexus- context-path)

vim ./nexus-3.13.0-01/etc/nexus-default.properties

image.png
  • application-port:http端口
  • application-host:
  • nexus-context-path:http端口后面的路径

启动

#进入bin目录
cd nexus-3.13.0-01/bin/
#启动
./nexus start

3. 访问

地址:http://ip:{application-port}/{nexus-context-path}

ip:私服所在服务器
{application-port}:nexus-default.properties文件配置的值
{nexus-context-path}:nexus-default.properties文件配置的值

此时是以游客身份进入的,点击右上角登陆。
账号:admin
密码:admin123

进入之后记得修改密码

二、使用私服步骤

配置代理仓库

1. 进入仓库配置页面

操作步骤如下:


image.png

图中我配置好的仓库信息

点击create repository进入


image.png

2. 配置代理仓库

image.png

下面是我配置的几个代理仓库

  • aliyun:http://maven.aliyun.com/nexus/content/groups/public/
  • spring-releases:https://repo.spring.io/release/
  • spring-snapshots:https://repo.spring.io/libs-snapshot/
  • spring-milestones:https://repo.spring.io/libs-milestone/
把配置的代理仓库加入到maven- public group中
image.png image.png

配置完成之后保存即可

3. 创建用户

这里的账户会用于连接私库。


image.png image.png

三、私服的使用

本地maven settings.xml配置

本地仓库位置

<settings>
  <localRepository>/Users/zhaoj/dev/work/platform/repository</localRepository>
</settings>

server配置

<settings>
  <servers>
    <server>
      <id>xx-release</id>
      <username>your-username</username>
      <password>your-password</password>
    </server>
    <server>
      <id>xx-snapshots</id>
      <username>your-username</username>
      <password>your-password</password>
    </server>
    <server>
      <id>xx-center</id>
      <username>your-username</username>
      <password>your-password</password>
    </server>
  </servers>
</settings>

镜像配置

<settings>
  <mirrors>
    <mirror>
      <id>xx-center</id>
      <mirrorOf>center</mirrorOf>
      <name>xxxx</name>
      <url>http://ip:{application-port}/{nexus-context-path}/repository/maven-public/</url>
    </mirror>
  </mirrors>
</settings>

私服仓库配置

<settings>
  <profiles>
    <profile>
      <id>maven-repo</id>
      <activation>
        <jdk>1.8</jdk>
      </activation>

      <repositories>
        <repository>
          <id>xx-center</id>
          <name>Repository for xxxx</name>
          <url>http://ip:{application-port}/{nexus-context-path}/repository/maven-public/</url>
          <layout>default</layout>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
</settings>

启动私服仓库

<settings>
  <activeProfiles>
    <activeProfile>maven-repo</activeProfile>
  </activeProfiles>
</settings>

maven项目pom.xml配置

自动提交jar进私服

pom.xml文件中添加

<project>
    <distributionManagement>
        <repository>
            <id>xx-release</id>
            <url>http://ip:{application-port}/{nexus-context-path}/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>xx-snapshots</id>
            <url>http://ip:{application-port}/{nexus-context-path}/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
</project>

运行mvn deploy即会提交jar进私服仓库。

相关文章

网友评论

      本文标题:nexus搭建maven私服

      本文链接:https://www.haomeiwen.com/subject/pbzagktx.html