您的位置:首页 > 其它

使用Nexus搭建Maven代理仓库

2014-04-09 11:16 561 查看
首先介绍一下背景,公司访问外网有限制,项目组大部分人员不能访问maven的central repository,因此在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到这台私服上

环境是:nexus-2.1.1、maven-3.0.4、jdk-1.6.0_32

一、用admin用户登陆nexus

nexus的下载和安装都很简单,网上也有很多介绍,本文就不重复了。主要介绍一下安装之后的配置

nexus的配置需要用admin角色完成,默认的密码是admin123,进入nexus首页之后,点击右上角,进行登录



然后就可以在左边的菜单中进行配置了



二、为nexus配置代理服务器

由于这台机器需要通过代理才能访问外网,所以首先要配置代理服务器,在Administration-->Server中进行配置



配置之后,nexus才能连上central repository,如果私服所在机器可以直接上外网,则可以省略这一步

三、配置repository

在Views/Repositories-->Repositories里进行配置



nexus里可以配置3种类型的仓库,分别是proxy、hosted、group

proxy是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用

hosted是宿主仓库,用户可以把自己的一些构件,deploy到hosted中,也可以手工上传构件到hosted里。比如说oracle的驱动程序,ojdbc6.jar,在central repository是获取不到的,就需要手工上传到hosted里

group是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了

nexus装好之后,已经初始化定义了一些repository,我们熟悉之后,就可以自行删除、新增、编辑

右边那个Repository Path可以点击进去,看到仓库中artifact列表。不过要注意浏览器缓存。我今天就发现,明明构件已经更新了,在浏览器里却看不到,还以为是BUG,其实是被浏览器缓存了

四、配置Central Repository的proxy

最关键的一个配置,可能就是Central Repository的proxy配置,因为大部分的构件,都是要通过这个proxy得到的



在安装完nexus之后,这个proxy是预置的,需要做的就是把Download Remote Indexes改为true,这样nexus才会从central repository下载索引,才能在nexus中使用artifact search的功能

网络上有一些其他公开的maven仓库,可以用同样的办法,在nexus中设置proxy,但是并不是所有maven仓库,都提供了nexus index,这种情况下,就无法建立索引了

五、配置hosted repository

一般会配置3个hosted repository,分别是3rd party、Snapshots、Releases,分别用来保存第三方jar(典型的比如ojdbc6.jar),项目组内部的快照、项目组内部的发布版



这里并没有什么特别的配置,只是Deployment Policy这个选项,一般Snapshots会配置成允许,而Releases和3rd party会设置为禁止

六、配置group repository

前面说过,group其实是一个虚拟的仓库,通过对实体仓库(proxy、hosted)进行聚合,对外暴露一个统一的地址



这里要注意的是,放到左边的仓库,才是会被聚合的仓库。我昨天一直搞错了,把仓库都放到右边,结果group什么都没有聚合到,是一个空的仓库。。。

七、配置用户密码

在Security-->Users中配置,在deployment用户上点击右键,选择Set Password,然后设置一个密码,做这个操作是为了后面提交做准备



八、在用户机器上配置settings.xml

经过前面的7个步骤,nexus就配置好了,接下来需要在每个开发人员的开发机器上进行配置了

配置文件在%USER_HOME%/.m2/settings.xml

Xml代码


<?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">
<servers>

<server>

<id>nexus-snapshots</id>

<username>deployment</username>

<password>deployment</password>

</server>

</servers>

<mirrors>

<mirror>

<id>nexus</id>

<name>internal nexus repository</name>

<url>http://10.78.68.122:9090/nexus-2.1.1/content/groups/public/</url>

<mirrorOf>central</mirrorOf>

</mirror>

</mirrors>

</settings>

这里只配置了2个元素<mirrors>和<servers>

首先这里配置了一个id为nexus的镜像仓库,地址是前面配置的public group的URL,然后镜像目标是central

maven里的超级pom,里面配置了这样一段:

Xml代码


<repositories>

<repository>

<id>central</id>

<name>Central Repository</name>

<url>http://repo.maven.apache.org/maven2</url>

<layout>default</layout>

<snapshots>

<enabled>false</enabled>

</snapshots>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>central</id>

<name>Central Repository</name>

<url>http://repo.maven.apache.org/maven2</url>

<layout>default</layout>

<snapshots>

<enabled>false</enabled>

</snapshots>

<releases>

<updatePolicy>never</updatePolicy>

</releases>

</pluginRepository>

</pluginRepositories>

因此,当本地的maven项目,找不到需要的构件(包括jar包和插件)的时候,默认会到central里获取

所以我们刚刚配置的镜像仓库,id也是central,这样本地maven项目对central repository的请求,就会转到镜像仓库上,也就是我们设置的nexus私服上

由于我们在项目的pom里,不会再配置其他的<repositories>和<pluginRepositories>元素,所以只要配置一个central的mirror,就足以阻止所有的外网访问。如果pom中还配置了其他的外网仓库,比如jboss repository等,可以把<mirrorOf>改为*

至于<servers>元素,是因为我们把项目内部的构件上传到nexus的仓库中时,nexus会进行权限控制,所以这里需要设置权限相关的信息。注意这里的<id>nexus-snapshots</id>,和后面maven工程里的pom设置是一致的

由于我们这里已经屏蔽了对外网仓库的请求,所以就不需要配置代理服务器了,如果需要配置代理服务器,可以用<proxies>元素

九、配置maven项目的pom文件

下面是简化后的pom文件:

Xml代码


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.huawei.inoc.wfm.task</groupId>

<artifactId>task-sla</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>task-sla</name>

<!-- 配置部署的远程仓库 -->

<distributionManagement>

<snapshotRepository>

<id>nexus-snapshots</id>

<name>nexus distribution snapshot repository</name>

<url>http://10.78.68.122:9090/nexus-2.1.1/content/repositories/snapshots/</url>

</snapshotRepository>

</distributionManagement>

</project>

这里配置了<distributionManagement>元素,其中的<id>nexus-snapshots</id>,与前面说的settings.xml中的<servers>元素中的配置必须一致

配置这个的目的,是当执行maven deploy时,才知道要将生成的构件部署到哪个远程仓库上,注意这里的URL填的就不是public group的地址:
http://10.78.68.122:9090/nexus-2.1.1/content/groups/public/
而是snapshots的地址:
http://10.78.68.122:9090/nexus-2.1.1/content/repositories/snapshots/
但是在nexus中,snapshots也是聚合到public group里的,所以开发人员A提交到snapshots的构件,开发人员B也可以从public group里获取到

十、eclipse中的设置

经过前面的配置,已经可以通过命令行进行maven操作了。不过实际开发中,一般都是使用eclipse的m2e插件,所以还需要对eclipse进行一些额外的配置

在Preferences-->Maven-->User Settings中,点击Update Settings,加载刚才我们对settings.xml的更改



然后在Maven Repositories视图里,可以看到仓库的情况



可以看到,从超级pom继承来的central被置灰了,不可用,后面的mirrored by nexus表示对该仓库的所有请求,都会转到镜像nexus中

十一、nexus的目录结构

nexus会安装在%USER_HOME%/sonatype-work/nexus下,有以下目录



其中的storage目录,就是构件实际存放的地址了

二:


maven学习笔记(四)仓库、nexus私服

构件:在maven中,任何一个依赖(jar包)、插件(maven-compiler-plugin-2.5.1.jar)或者项目输出(前面例子中运行mvn clean install部署到本地仓库的jar包)都称为构件。

仓库:maven在某一位置存储所有共享的构件,这个统一的位置就是仓库。

仓库分类:maven仓库分为本地仓库和远程仓库

本地仓库:在本地机器上缓存构件的文件目录(如前面例子中的D:\dev_env\maven)

安装好maven后,本地仓库目录是不存在的。当用户输入第一条maven命令,maven才会创建本地仓库

maven本地仓库布局:(也可以说是jar包在本地仓库中的路径,此处只是说明常规的布局)

maven是根据构件(jar包)的GAV属性来定义构件存在的路径的,例如某个构件的GAV属性是

<groupId>com.sun.xml.bind</groupId>

<artifactId>jaxb-xjc</artifactId>

<version>2.2.6</version>

maven首先将groupid属性值中的点号替换成文件路径分隔符 / ,根据上面的例子即为 com/sun/xml/bind ,然后加上artifactId,再加上version,最终路径就是 com/sun/xml/bind/jaxb-xjc/2.2.6 ,所以构件存放的目录就应该是本地仓库目录下的 com/sun/xml/bind/jaxb-xjc/2.2.6
目录下。

远程仓库:包括中央仓库、私服和其他公共库

私服:是一种特殊的远程仓库,代理缓存远程仓库(可以是默认的中央仓库、可以是第三方的公用仓库)的构件。本地maven用户需要下载构件时,从私服请求。若私服中找不到构件,就从远程仓库(中央仓库或其他公共库)下载,缓存在私服上,供用户下次请求。 若一些无法从外部远程仓库下载的构件,可以从本地上传到私服上供maven用户请求。

nexus私服的搭建和应用

nexus搭建:

1、下载地址:http://www.sonatype.org/nexus/archived(win:zip包 linux :tar.gz)

2、将下载后的zip包解压缩,然后配置环境变量,在path变量后添加nexus的bin路径(本地环境路径为:D:\nexus-2.7.0-bundle\nexus-2.7.0-04\bin)

3、在控制台(cmd)下运行nexus install命令将nexus安装到windows的服务中(可到系统的服务中查看)

4、在控制台(cmd)下运行nexus start命令

5、在浏览器中输入http://ip:8081/nexus即可访问搭建的nexus私服(URL中的ip为本机ip)

nexus的默认端口是可以手动更改的(修改D:\nexus-2.7.0-bundle\nexus-2.7.0-04\conf\nexus.properties文件中的application-port属性值,重启nexus)

6、点击页面右上角的log in,输入用户名(默认admin)和密码(默认admin123)

nexus仓库

点击页面左边的Repositories可以在界面上显示nexus下所有的仓库

如下图,根据type字段可以将仓库分为:hosted、proxy、group、virtual

1、hosted的仓库:内部项目的发布仓库(如前面例子中执行mvn clean install命令发布项目,最终发布的jar包回放入hosted仓库)

3rd party仓库存储用户手动上传的构件,这些构件不能从中央仓库下载,在仓库的Artifact Upload页签中可以执行



2、proxy的仓库:从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径)

3、group仓库:组仓库用来方便开发人员进行设置的仓库

group仓库可以自由组合其他的仓库为一个组,然后在项目的pom文件的repository可以配置这个仓库

nexus仓库设置

1、更新私有仓库索引

点击Repository名称为Central,type为proxy的仓库,在页面下方的Configuration页,把 Download Remote Indexes的值改为True,然后点击最下面的save按钮。(更新索引的时间有点长,请耐心等待。更新完索引后可在Browse Index页签点击刷新按钮就可显示所有更新后的索引,展开索引树,点击到叶子节点--依赖jar包,可查看其依赖配置坐标。)

可以在页面左上角的Artifact Search搜索框中输入要搜索的依赖(如:spring),就会显示搜索到的依赖配置坐标。

由于自动更新索引时间较长,也可以手动下载包含索引文件的压缩包nexus-maven-repository-index.zip,然后放入Central仓库索引存储的目录(本地路径为D:\nexus-2.7.0-bundle\sonatype-work\nexus\indexer\central-ctx ,这种方式未经验证,压缩包下载失败,第一种自动更新可以成功)。

2、配置镜像

修改本地仓库的配置文件D:\dev_env\maven\settings.xml,在mirrors节点下添加如下配置

[html] view
plaincopy





<mirror>

<id>central</id>

<mirrorOf>*</mirrorOf>

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

<url>http://192.168.19.38:8081/nexus/content/groups/public/</url>

</mirror>

mirrorOf配置为*,表示这个镜像配置适用于所有的仓库,是所有仓库的一个镜像,maven无论要去那个仓库下载构建都会跳转到镜像URL(此时配置的是nexus的group类型的仓库地址,该组仓库包含了其他几个类型的仓库,可以点击这个仓库,查看其Configuration页签)去下载。

mirrorOf也可以配置一个或多个仓库,多个仓库配置值要与对应的仓库id一致,以逗号分隔。

项目的发布:

1、配置发布仓库路径

在user-parent的pom文件的project节点下添加项目发布仓库信息。snapshotRepository配置快照版本发布仓库路径(由于使用的例子定义的都是快照版本,所以项目都会发布到user-snapshots这个仓库中,对应的是nexus上与配置URL匹配的仓库);repository配置release版本发布仓库路径。url属性定义最终发布到的nexus仓库路径。

[html] view
plaincopy





<distributionManagement>

<snapshotRepository>

<id>user-snapshots</id>

<name>User Project SNAPSHOTS</name>

<url>http://192.168.19.38:8081/nexus/content/repositories/snapshots/</url>

</snapshotRepository>

<repository>

<id>user-releases</id>

<name>User Project Release</name>

<url>http://192.168.19.38:8081/nexus/content/repositories/releases/</url>

</repository>

</distributionManagement>

2、授权

项目发布的时候需要配置一个有发布权限的用户(nexus有个默认的用户deployment,默认密码deployment123),nexus仓库会鉴权,修改本地仓库的配置文件D:\dev_env\maven\settings.xml,在servers节点下添加如下配置

[html] view
plaincopy





<server>

<id>user-snapshots</id>

<username>deployment</username>

<password>deployment123</password>

</server>

<server>

<id>user-releases</id>

<username>deployment</username>

<password>deployment123</password>

</server>

3、发布

在springsource中导入user-parent及其子项目,运行user-parent下的pom文件 clean deploy

发布成功后可以到<url>http://192.168.19.38:8081/nexus/content/repositories/snapshots/</url>对应的nexus仓库的Browse Storage页签下查看,会显示所有项目的jar包



可下载项目示例:http://download.csdn.net/detail/liuxigiant/6691645

示例出自视频教程的maven第二部分,视频下载路径/content/1772795.html

三:


exus搭建maven私服

公司的maven私服跑了两年多了,最近朋友让帮忙给他搭建maven私服。这里做个总结吧。首先,先问个问题,有公共的maven仓库服务器,为什么还要搭建maven私服呢?在本地搭建后有如下几个优点:1、加速构建;2、节省带宽;3、节省中央maven仓库的带宽;4、稳定(应动一旦中央服务器出问题的情况);5、控制和审计;6、能够部署第三方构件;7、可以建立本地内部仓库;8、可以建立公共仓库。有这么多优点还不足以吸引你吗?


一、nexus下载安装


1、nexus的安装

官方下载归档页面为:http://www.sonatype.org/nexus/archived

在上面的页面上可以下载到目前的所有版本的nexus ,目前的最新版本为2.7.2 ,官方提供了tar、war、zip三种格式的下载。我这里下载的是zip包。

#cd /App
#mkdir nexus
#cd nexus
#wget http://download.sonatype.com/nexus/oss/nexus-2.7.2-bundle.zip #unzip nexus-2.7.2-bundle.zip
#cd nexus-2.7.2/bin
#sh nexus start


注:nexus由于是java语言开发的,所以依赖java环境,要先确认主机上有java环境,如果是windows主机请启动nexus.bat或bin/jsw/windows-x86-32(或64)的相应目录下去启动或安装服务。

报错1:

[root@localhost bin]# sh nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.


上面的错误原因很简单,因为使用了root用户。解决方法很简单,新建一个用户nexus也好,www也好,然后赋予权,重启。
#useradd www
#chown www:www /App/nexus
#su  www
#sh nexus start


报错2:
wrapper  | JVM exited while loading the application.
jvm 5    | Exception in thread "main" java.lang.UnsupportedClassVersionError: org/sonatype/nexus/bootstrap/jsw/JswLauncher : Unsupported major.minor version 51.0
jvm 5    |      at java.lang.ClassLoader.defineClass1(Native Method)
jvm 5    |      at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
jvm 5    |      at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
jvm 5    |      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
jvm 5    |      at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
jvm 5    |      at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
jvm 5    |      at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
jvm 5    |      at java.security.AccessController.doPrivileged(Native Method)
jvm 5    |      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
jvm 5    |      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
jvm 5    |      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
jvm 5    |      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
jvm 5    | Could not find the main class: org.sonatype.nexus.bootstrap.jsw.JswLauncher.  Program will exit.
wrapper  | There were 5 failed launches in a row, each lasting less than 300 seconds.  Giving up.
wrapper  |   There may be a configuration problem: please check the logs.
wrapper  | <-- Wrapper Stopped


经在网上查到原因是,最新版本的maven需要依赖java1.7,该问题在公司的nexus升级时也遇到过。这里只是为了做演示,懒得在测试机上更换jdk了,直接下了nexus-2.5的版本。然后重新做上面的步骤。

报错3:

ception: Address already in use
jvm 1    | java.net.BindException: Address already in use
jvm 1    |      at sun.nio.ch.Net.bind(Native Method) ~[na:1.6.0_29]


因为默认的8081端口,已经被另外一个程序占有了,vim /App/nexus/nexus-2.5.0-04/conf/nexus.properties ,找到application-port=8081更改下端口,然后重新启动。通过http://IP:端口就可以访问了,登录以后,右上角有登录选项,默认用户名密码是admin/admin123 。


2、nginx反向代理nexus

server {
listen 80;
server_name maven.361way.com; //配置的域名
location / {
proxy_pass  http://127.0.0.1:8081; //跳转到的地址
proxy_redirect  off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
}
}





二、nexus配置


1、ldap认证

如下图所示,依次选择左侧的security-->LDAP Configuration,后按下面的配置进行配置:









操作方法security->roles->add->External Role

Mapping,Realm选择LDAP,Role里如果没有数据,说明ldap没设置好,Role里选择一个组,点击create mapping。

然后在configuration中选择add,添加两个权限,一个是Nexus deployment role,一个是All maven repositories (Full control)。

然后在对应组的小伙伴们就有权限了。


2、nexus仓库

nexus有四种仓库:group(仓库组)、hosted(宿主)、proxy(代理)、virtual(虚拟),首次登录后会发现一个公共组仓库,其包含以下内容。

Public Repositories: 仓库组

3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库
Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
Central: 用来代理maven中央仓库中发布版本构件的仓库
Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
Releases: 用来部署管理内部的发布版本构件的宿主类型仓库
Snapshots:用来部署管理内部的快照版本构件的宿主类型仓


3、配置远程索引

新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。点击左边Administration菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache

Snapshots,Codehaus Snapshots和Maven

Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。





这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index ,如查看到有索引目录,表示已经OK 。

注:这个可以根据自己的实际需要去设置,以避免都开启的话一是会占用带宽(大量的下载远程文件),二是有可能会有爆仓的可能(这个在后面也会提到) 。


4、建立宿主仓库

新 建公司的内部仓库,步骤为Repositories –> Add –> Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,比如分别填入test 和 test repostiory,另外把Deployment Policy设置为Allow Redeploy,点击save就创建完成了。









5、Nexus仓库组

Nexus

中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据

groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者

proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。

neuxs默认自带了一个名为“Public

Repositories”组,点击该组可以对他保护的仓库进行调整,把刚才建立的公司内部仓库test

repostiory加入其中,这样就不需要再在maven中明确指定内部仓库 的地址了。同时创建一个Group

ID为public-snapshots、Group Name为Public Snapshots

Repositories的组,把Apache Snapshots、Codehaus Snapshots、Snapshots和zfy

repostiory加入其中。











三、maven客户端配置

maven客户端的settings.xml文件

#vim /App/maven/conf/settings.xml
<?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"> <pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.361way.com/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.361way.com/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>


注:settings文件中在配置ldap认证时,由于默认保存的是明文密码,这样就导致不十分安全,可以通过mvn --encrypt-master-password 密码的方式生成加密过的密码文件。这个是需要mvn版本支持的,具体可以查看官方文档及配置说明。

maven项目下的pom.xml文件

<distributionManagement>
<!-- 两个ID必须与 setting.xml中的<server><id>nexus-releases</id></server>保持一致-->  <repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://maven.361way.com/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://maven.361way.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>



四、注意事项


1、爆仓问题的解决方法

login->scheduled tasks->add,添加一个定时清理目录的计划任务即可。最后一个选项“remove if released”需要慎重,平时开发可能不是特别正规的时候可能会snapshot和release都需要。


2、减少后端压力

该方法也是从网上了解到的,可以通过前端nginx开启cache功能减少后端nexus maven仓库的压力。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: