使用nexus搭建maven私服
简 介
nexus是一个强大的maven仓库管理器,它极大的简化了本地内部仓库的维护和外部仓库的访问
nexus是一套开箱即用的系统不需要数据库,它使用文件系统加Lucene来组织数据
nexus使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过IDEA和Eclipse集成使用
nexus支持webDAV与LDAP安全身份认证
nexus提供了强大的仓库管理功能,构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,占用较少的内存,基于简单文件系统而非数据库
使用的理由
1.节省外网带宽。
2.加速Maven构建。
3.部署第三方构件。
4.提高稳定性,增强控制。
5.降低中央仓库的负荷。
6.控制和审计
7.建立本地内部公用仓库
8.安全
仓库类型介绍
hosted,本地仓库,通常我们会部署自己的构件到这一类型的仓库。比如公司的第二方库
proxy,代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库
group,仓库组,用来合并多个hosted/proxy仓库,当你的项目希望在多个repository使用资源时就不需要多次引用了,只需要引用一个group即可
环境准备
# 首先安装好 JDK + Maven,永久关闭防墙火
[root@nexus /]# systemctl disable firewalld && systemctl stop firewalld
开始搭建
链接:https://pan.baidu.com/s/14UqGujdk5tYr_WonTwLOIg
提取码:fx4n
[root@nexus opt]# pwd
/opt
[root@nexus opt]# ls -l
-rw-r--r--. 1 root root 82413789 2月 27 23:46 nexus-2.14.14-01-bundle.tar.gz
[root@nexus opt]# tar -zxvf nexus-2.14.14-01-bundle.tar.gz
[root@nexus opt]# mv nexus-2.14.14-01 nexus && cd nexus
[root@nexus nexus]# vim bin/nexus
RUN_AS_USER=root
[root@nexus nexus-2.14.14-01]# ./bin/nexus start
访问:ip:8081/nexus
默认账号/密码:admin/admin123
集成maven
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">
<localRepository>D:\apache-maven-3.6.3\repo</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>release</id>
<name>Releases</name>
<!--镜像采用配置好的组的地址-->
<url>http://192.168.86.128:8081/nexus/content/groups/public/</url>
<mirrorOf>!internal.repo,*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>default_profile</id>
<repositories>
<!--包含需要连接到远程仓库的信息 -->
<repository>
<!--远程仓库唯一标识 -->
<id>releases</id>
<!--远程仓库名称 -->
<name>Releases</name>
<!--如何处理远程仓库里发布版本的下载 -->
<releases>
<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
<enabled>true</enabled>
<!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。
这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。
-->
<updatePolicy>never</updatePolicy>
<!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。 -->
<checksumPolicy>warn</checksumPolicy>
</releases>
<!--如何处理远程仓库里快照版本的下载。有了releases和snapshots这两组配置,POM就可以在每个单独的仓库中,为每种类型的构件采取不同的策略。 -->
<snapshots>
<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
<enabled>true</enabled>
<!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。
这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。
-->
<updatePolicy>always</updatePolicy>
<!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。 -->
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<!--远程仓库URL,按protocol://hostname/path形式 -->
<url>http://192.168.86.128:8081/nexus/content/groups/public/</url>
<!--用于定位和排序构件的仓库布局类型-可以是default(默认)或者legacy(遗留)。Maven 2为其仓库提供了一个默认的布局; -->
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>releases</id>
<name>Maven China Mirror</name>
<url>http://192.168.86.128:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
- 配置项目
pom.xml文件
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>provided</scope>
</dependency>
......
</dependencies>
<!-- 在pom.xml配置上传该项目 -->
<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.86.128:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.86.128:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
执行命令
mvn clean package deloy

浙公网安备 33010602011771号