Sonatype Nexus 搭建maven私服

来源:互联网 发布:淘宝教育可以下载吗 编辑:程序博客网 时间:2024/06/05 18:21

系统版本:ubuntu-14.04.4-server 64-bit
maven版本:apache-maven-3.3.9
java版本:1.7.0_121 64-bit


搭建maven私服之前需要了解的几个名词

Proxy Repository 代理仓库
A Proxy Repository is a proxy of a remote repository. By default, Nexus Repository Manager ships with the following configured proxy repositories
Apache Snapshots/Codehaus Snapshots/Central
代理仓库就是远程仓库的代理。默认Nexus仓库管理自带三种代理仓库
Apache Snapshots/Codehaus Snapshots/Central

Hosted Repository 宿主仓库
A Hosted Repository is a repository that is hosted by the repository manager. Nexus Repository Manager ships with the following configured hosted repositories
3rd Party/Releases/Snapshots
宿主仓库就是被仓库管理者持有的仓库,Nexus仓库管理自带三种宿主仓库
3rd Party/Releases/Snapshots

Virtual Repository 虚拟仓库(基本没用过)
A Virtual Repository serves as an adaptor to and from different types of repositories
虚拟仓库作为一个适配器来对不同类型的仓库进行转换(例如maven 1/ 2之间转换)

Repository Group 仓库组
看名字就知道,一些其它仓库的组合,不具有实际仓库的功能,只是对现有的仓库组织起来,客户端请求的还是实际配置的仓库

SNAPSHOT(快照版本)
在maven中SNAPSHOT版本代表正式发布(release)的版本之前的开发版本,在pom中用x.y-SNAPSHOT表示

RELEASE(发布版本,稳定版本)
在maven中RELEASE代表着稳定的版本,unchange,不可改变的,在maven中SNAPSHOT与RELEASE版本在策略上是完全不同的方式,SNAPSHOT会根据你的配置不同,频繁的从远程仓库更新到本地仓库;而RELEASE则只会在第一次下载到本地仓库,以后则会先直接从本地仓库中寻找


下载Nexus Repository OSS开源版本
下载地址
https://www.sonatype.com/download-oss-sonatype
文档
http://books.sonatype.com/nexus-book/reference/index.html

下载方式
可以先下载好,然后拷贝过去,或者在服务器上使用wget直接下载
wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.1-01-bundle.tar.gz
解压缩文件
tar xvzf nexus-2.14.1-01-bundle.tar.gz
进入nexus-2.14.1-01/bin目录,启动 $: ./nexus start
启动成功
Starting Nexus OSS…
Started Nexus OSS.
配置文件位置为nexus-2.14.1-01/conf/nexus.properties,默认端口8081,webapp为nexus,日志文件nexus-2.14.1-01/logs/wrapper.log
启动之后,可以通过tail -f logs/wrapper.log 在终端事实监视日志输出
工作目录为sonatype-work

nexus-2.14.1-01/bin/jsw/conf/wrapper.conf 为Jetty servlet容器启动的核心配置文件,可以对java内存配置、java虚拟机参数配置、log日志文件配置等

进入系统 http://192.168.1.84:8081/nexus,如图
这里写图片描述

工作目录为sonatype-work
这里写图片描述

开启代理仓库的Download Remote Indexes,直接维护远程仓库索引,来达到快速搜索组件
这里写图片描述

比较常用的几个公共仓库地址:
http://repo1.maven.org/maven2/
http://central.maven.org/maven2/
http://repository.jboss.org/nexus/content/groups/public/
本来以为aliyun也是仓库内,但是试了一下,发现应该就是镜像,access forbidden请求拒绝
http://maven.aliyun.com/nexus/content/groups/public/

添加代理仓库
这里写图片描述

这里以添加ibiblio Repository为例http://maven.ibiblio.org/maven2/
这里写图片描述

把ibiblio Repository添加到仓库组
默认,nexus会给你创建一个仓库组,现在就把他添加到这个默认的仓库组里
这里写图片描述

  • 注意顺序,这里的顺序会影响到你搜索组件的顺序,默认搜索组件的顺序是releases(本机发布版)>snapshots(本机快照)>3rd part(本机下载的第三方插件)>central(远程代理中央仓库)> ibiblio(远程ibiblio代理仓库,在国内速度还是比较快的,可以放到中央仓库的前面)

注:可以从Routing中查看代理仓库的状态

这里写图片描述

添加第三方组件(oracle)
这里写图片描述

可以看到在仓库中已经存在,并且在仓库组中也可以看到,同时,也能在索引中找到
这里写图片描述

查看你的工作目录,可以看到oracle的jdbc驱动已经下载到仓库本地
这里写图片描述


使用私服地址配置本地仓库

两种方式,一是在maven的配置文件中全局配置;二是在所在的项目pom文件中配置,只针对本项目的

一、 全局配置
这里采用覆盖默认的central仓库的方式,即所有的组件都通过我们自己的nexus私服下载,修改maven配置文件settings.xml

<mirrors>  <mirror>    <id>nexus</id>    <mirrorOf>*</mirrorOf>    <url>http://192.168.1.86:8081/nexus/content/groups/public/</url>  </mirror></mirrors><profiles>  <profile>    <id>nexus</id>    <repositories>      <repository>        <id>central</id>        <url>http://any-site.unimportant</url>        <releases><enabled>true</enabled></releases>        <snapshots><enabled>true</enabled></snapshots>      </repository>    </repositories>    <pluginRepositories>      <pluginRepository>        <id>central</id>        <url>http://any-site.unimportant</url>        <releases><enabled>true</enabled></releases>        <snapshots><enabled>true</enabled></snapshots>      </pluginRepository>    </pluginRepositories>  </profile></profiles><activeProfiles>  <activeProfile>nexus</activeProfile></activeProfiles>

二、pom文件配置

<repositories>  <repository>    <id>nexus</id>    <url>http://192.168.1.86:8081/nexus/content/groups/public/</url>    <releases>      <enabled>true</enabled>    </releases>    <snapshots>      <enabled>true</enabled>    </snapshots>  </repository></repositories><pluginRepositories>  <pluginRepository>    <id>nexus</id>    <url>http://192.168.1.86:8081/nexus/content/groups/public/</url>    <releases>      <enabled>true</enabled>    </releases>    <snapshots>      <enabled>true</enabled>    </snapshots>  </pluginRepository></pluginRepositories>

这时我们在dependency中加入

<dependency>  <groupId>commons-fileupload</groupId>  <artifactId>commons-fileupload</artifactId>  <version>1.3.2</version></dependency>

更新maven依赖,会发现仓库中下载了common-fileupload的组件

这里写图片描述
这里写图片描述


发布组件到私服仓库

首先你需要nexus发布组件的权限的用户名/密码
这里写图片描述

修改maven配置文件settings.xml

<servers>  <server>    <id>deploymentRepo</id>    <username>admin</username>    <password>admin123</password>  </server>  <!-- Another sample, using keys to authenticate.  <server>    <id>siteServer</id>    <privateKey>/path/to/private/key</privateKey>    <passphrase>optional; leave empty if not used.</passphrase>  </server>  --></servers>

同时在pom文件中增加如下分发配置,发布到私服下的snapshots下面,注意id必须与settings.xml中一致

<distributionManagement>  <repository>    <id>deploymentRepo</id>    <name>ProjectSnapshots</name>    <url>http://192.168.1.86:8081/nexus/content/repositories/snapshots/</url>  </repository></distributionManagement>

我的测试项目pom如下
这里写图片描述

在终端执行
mvn deploy -Dmaven.test.skip=true
这里写图片描述

在nexus上可以看到
这里写图片描述

成功分发到私服!

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孕中期吃了荠菜怎么办 孕妇吃了荠荠菜怎么办 刚怀孕吃了荠菜怎么办 孕妇误吃了荠菜怎么办 手刮了芋头很痒怎么办 手弄了芋头很痒怎么办 削完芋头皮手痒怎么办 洗完芋头后手痒怎么办 芋头的汁非常痒怎么办 孕妇吃了木耳菜怎么办 宝宝体检本丢了怎么办 家具长霉长虫了怎么办 喝了发霉的水怎么办 饭店刚开业生意不好怎么办 牙不能咬硬东西怎么办 甲鱼头不伸出来怎么办 咸鸭蛋腌的太咸怎么办 煮熟的鸭蛋不咸怎么办 羊腰子上的肥油怎么办 高漫sai没有压感怎么办 sai上面没有笔压怎么办 pr视频导不出来怎么办 脏辫头发长长了怎么办 脏辫发根长出来怎么办 白鞋前面踢破了怎么办 皮鞋破了一点皮怎么办 白色皮鞋破皮了怎么办 买的鞋鞋底太滑怎么办 鞋底磨平了很滑怎么办 包体马桶盖松了怎么办 箭牌马桶盖松了怎么办 送丝软管堵了怎么办 钢笔干了不出水怎么办 凌美钢笔不出水怎么办 新钢笔写不出水怎么办 新买的钢笔太粗怎么办 门锁螺丝拧花了怎么办 手机螺丝拧花了怎么办 电脑螺丝滑丝了怎么办 打了羽毛球手痛怎么办 小孩屁股打红了怎么办