[转] Nexus OSS 3.xx 体验

【From】 https://blog.csdn.net/qq250782929/article/details/51605965

 

Nexus Manager OSS 3.0 —Maven Repository

前言

网上基本搜不到 Nexus 3.0 版本以上的相关配置文档,最近刚好在弄,就顺便写下来了,当作笔记。
nexus官方文档

1.下载

下载地址:
http://www.sonatype.com/download-oss-sonatype

选择对应的版本下载,本文章以nexus-3.0.0-03-win64.zip版本为例。(其他版本大同小异)

Nexus 3.xx 版本除了Maven以外还支持 Docker ,NuGet ,npm ,Bower 。有时间的可以尝试一下。

2.解压

将下载好的zip格式的解压到指定目录。(Windows用户需注意目录路径不能含有中文,空格等字符

3.执行

3.0版本:进入到nexus的bin目录 nexus /start 执行

cd D:
exus-3.0.0-03in
D:
exus-3.0.0-03in>nexus /start

3.2版本:进入到nexus的bin目录 nexus /start 执行

cd D:
exus-3.0.0-03in
D:
exus-3.0.0-03in>nexus.exe /run

默认应用地址是http://localhost:8081,若需要更改:
3.0版本:

打开 ..
exus-3.0.0-03etcorg.sonatype.nexus.cfg

修改端口: application-port

修改ip: application-host 

3.2版本:

打开 ..
exussonatype-work
exus3etc
exus.properties

修改端口: application-port

修改ip: application-host 

4.配置 Nexus

用浏览器打开 http://localhost:8081

点击右上角Sign in 按钮登录。默认用户名:admin,密码:admin123

点击齿轮状配置按钮,进入配置页面:

进入Repository-Repositories

Repository的type属性有:proxy,hosted,group三种。

proxy:即你可以设置代理,设置了代理之后,在你的nexus中找不到的依赖就会去配置的代理的地址中找

hosted:你可以上传你自己的项目到这里面

group:它可以包含前面两个,是一个聚合体。一般用来给客户一个访问nexus的统一地址。

简单的说,就是你可以上传私有的项目到hosted,以及配置proxy以获取第三方的依赖(比如可以配置中央仓库的地址)。前面两个都弄好了之后,在通过group聚合给客户提供统一的访问地址

至于format,因为本文讲的的 Maven Repository ,所以请选择maven2;

系统默认就有以上几个Repository。点击maven-public 确保已经将 maven-central,maven-releases以及maven-snapshots都包含在里面。

maven-releases : 默认配置只能上传 release版本的项目

maven-snapshots: 默认配置只能上传 snapshots版本的项目

如有特殊要求,可以自己创建一个Version policy 为Mixed的Repository。

以上配置就能满足一般需求了。

5.使用 mvn deploy 向 Nexus服务器 上传项目

maven setting.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>E:/repository</localRepository>
    <mirrors>
        <mirror>
         <!--This sends everything else to /public -->
         <id>nexus</id>
         <mirrorOf>*</mirrorOf>
         <url>http://localhost:8081/repository/maven-public/</url>
        </mirror>
    </mirrors>
    <servers>
        <server>
            <id>nexus</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
</settings>

localRepository:本地库的地址

mirror:nexus地址

servers:nexus服务器登录名和密码

1.使用cmd上传

mvn deploy:deploy-file -DgroupId=com.cxx -DartifactId=fu -Dversion=1.0.0 -Dpackaging=jar -Dfile=D:gworkspaceworkcxxfu	argetfu.jar -Durl=http://localhost:8081/repository/maven-releases/ -DrepositoryId=nexus -s D:maven-3.2.1confsettings.xml

参数说明:

-D 传入指定参数 分别对应pom中的 groupId,artifactId,version,packaging
file 本地jar的路径
url Repository Url (请选择对应release,snapshots或mixed的url)
repositoryId 对应setting.xml中server id
-s setting.xml的路径(如果使用默认conf中的setting,则无需配置)

2.使用IDE上传

项目中的pom文件添加

<distributionManagement>
    <repository>
      <id>nexus</id>
      <name>maven-releases</name>
      <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
</distributionManagement>

id:对应setting.xml中server id
name:nexus Repository name
url:nexus Repository url

然后使用IDE自带的Maven deploy就可以了。

然后就可以在nexus中看到你上传的:

这样你的maven项目就能引用你所上传的项目了。

原文地址:https://www.cnblogs.com/pekkle/p/9920487.html