windows搭建Nexus Maven私有仓库图文教程

Java工具 潘老师 来源:Arya777 12个月前 (04-12) 438 ℃ (0) 扫码查看

Nexus快速入门、安装

在公司开发测试过程中,内网团队使用一个服务来节省外网宽带以及缓存Maven Respository中没有的jar包,允许上传和下载私有库,并且不被外部访问,安全稳定

一、下载

官网下载地址,但是速度很慢,可以使用csdn资源链接获取

二、搭建服务

1、解压

解压好下载的nexus压缩包,会有以下两个文件:nexus-3.42.0-01和sonatype-work

2、安装

右键开始菜单打开管理员cmd,进入到nexus-3.42.0-01\bin目录下,执行:

.\nexus.exe /install nexus

将其安装到Windows服务中(因为已经安装过服务,所以再次执行会出现 “已安装”的提示)

3、运行

使用nexus.exe /start nexus.exe /stop 进行开启和关闭服务。或者执行nexus.exe /run来通过命令窗口方式执行。 (第一次启动会花费较长时间)
启动成功后,默认端口为8081,浏览器访问方式为:localhost:8081

4、修改端口

修改端口可以编辑nexus-3.42.0-01\etc\nexus-default.properties下的application-port属性

5、登录

点击右上角Sign in进行登录,默认用户名是admin,密码会随机生成在nexus\sonatype-work\nexus3下的password文件中,登录后即可修改密码。

三、配置私服

1、配置仓库

登录之后菜单栏左侧会有一个设置的图标,点击后再点Repositories进行配置仓库

1)maven-central,maven中央库,默认从https://repo1.maven.org/maven2/拉取jar (下载速度很慢,这就是下面一步创建阿里云代理的原因);
2)maven-releases:私库打包发行版jar;(可上传自编jar包)
3)maven-snapshots:私库快照版jar;(可上传自编jar包)
4)maven-public:仓库分组,把上面三个仓库组合在一起后对外提供服务,在本地maven setting.xml中配置;

2、创建阿里云代理仓库

点击Create repositories创建一个阿里云代理仓库 (跟在maven => Setting.xml更改阿里云镜像道理一样)
1)proxy:提供代理其它仓库的类型;
2)hosted:本地存储。像官方仓库一样提供本地私库功能;
3)group:组类型,能够组合多个仓库为一个地址提供服务;

阿里云镜像服务URL详见:仓库服务
点击最下方Create Repositories按钮创建完毕

4、 设置阿里云镜像优先

点击maven-public 设置阿里云镜像优先使用

四、在Maven中使用私服

1、设置maven conf下的setting.xml文件。

公司的小伙伴需共同将本地的setting.xml指向公司的nexus私有仓

<?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>E:\maven\mavenLocal</localRepository> <!-- 配置jar包存放位置 -->
<mirrors>
<!-- 配置本地仓库资源来源 -->
<mirror>
<id>maven-public</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<!-- 配置本地仓库访问私服的权限  nexus的 登录用户名密码 -->
<server>
<id>maven-releases</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
<!-- 属性列表配置 -->
<profiles>
<profile>
<id>my-profile</id>
<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>
<!-- 远程仓库列表 maven用来填充构建系统本地仓库所使用的一组远程仓库 -->
<repositories>
<repository>
<id>maven-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>http://localhost:8081/repository/maven-public</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>my-profile</activeProfile>     
</activeProfiles>
</settings>

2、上传jar包

往私有仓上传maven官方镜像中下载不到的jar包

3、往私有仓发布自编jar包

1)可使用第二步打包后手动上传
2)在需发布的项目pom文件中添加 distributionManagement配置,而后使用 idea 工具右侧的maven栏,点击 deploy 发布到远程仓库,而后登陆到你的nexus私服即可查看部署的jar包
package:完成了项目编译、单元测试、打包功能,但并没有把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库
install: 完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓3库,但没有布署到远程maven私服仓库
deploy:完成了项目编译、单元测试、打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库和远程maven私服仓库

<!--  maven仓库配置 deploy时可推送到对应的配置仓库中    -->
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus Releases Repository Pro</name>
<url>http://localhost:8081/repository/maven-releases/</url> <!--  正式版推送到这    -->
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshots Repository Pro</name>
<url>http://localhost:8081/repository/maven-snapshots/</url> <!--  测试版推送到这    -->
</snapshotRepository>
</distributionManagement>

以上就是windows搭建Nexus Maven私有仓库图文教程的全部内容,欢迎留言评论。


版权声明:本站文章,如无说明,均为本站原创,转载请注明文章来源。如有侵权,请联系博主删除。
本文链接:https://www.panziye.com/java/6186.html
喜欢 (0)
请潘老师喝杯Coffee吧!】
分享 (0)
用户头像
发表我的评论
取消评论
表情 贴图 签到 代码

Hi,您需要填写昵称和邮箱!

  • 昵称【必填】
  • 邮箱【必填】
  • 网址【可选】