使用nexus3x部署管理maven私服

来源:互联网 发布:人体数据 编辑:程序博客网 时间:2024/06/05 16:25

使用nexus3x部署管理maven私服

公司最近部署了个私服,本人就琢磨了琢磨,下面是一些过程和注意点:

  • 下载及安装(win64)
  • nexus基本操作
  • 分发第三方jar或者自己的项目
  • 管理依赖

一.下载及安装(win64)

1.下载
https://www.sonatype.com/oss-thank-you-win64.zip
2.修改端口:D:\MAVEN-PRIVATE-REPOSITORY\nexus-3.2.1-01-win64\nexus-3.2.1-01\etc\nexus-default.properties
这里写图片描述
3.安装启动服务
这里写图片描述
4.测试访问:
http://localhost:8088/#browse/welcome

二.nexus基本操作

1.登陆
默认管理员账户:
id:admin
password:admin123
这里写图片描述
2.修改管理员密码
这里写图片描述
这里写图片描述
这里写图片描述
设置新密码并确认,修改成功
这里写图片描述
3.新增用户
这里写图片描述
这里写图片描述
这里写图片描述
这里按需要自己随意填写记住id和password就可以了
4.nexus新建仓库
这里可以按照选择 proxy(代理类型)、hosted(宿主类型)、group(仓库组类型)选择新建
这里写图片描述
这里写图片描述
仓库类型很多,但是主要也就上面提到的三个,新建信息填写一下,没有多少要注意的
这里写图片描述
也可以不新建,直接使用自带的仓库,只需将 allow redeploy打开即可(基本不用新建);

三.分发第三方jar或者自己的项目

1.配置maven setting.xml(注意是安装目录下的)
1)配置仓库id及访问验证,第10点上传第三方同样处理

<settings>...<servers>  <server>    <id>maven-releases</id>    <username>admin</username>    <password>6771</password>  </server>  <server>    <id>maven-snapshots</id>    <username>admin</username>    <password>6771</password>  </server>  <server>    <id>3rdpart</id>    <username>admin</username>    <password>6771</password>  </server>...</settings>

2)配置分发目标仓库

<project>...<distributionManagement>   <repository>      <id>maven-releases</id>      <name>User Project Release</name>      <url>http://localhost:8088/repository/maven-releases</url>   </repository>   <snapshotRepository>      <id>maven-snapshots</id>      <name>User Project SNAPSHOTS</name>      <url>http://localhost:8088/repository/maven-snapshots/</url>   </snapshotRepository></distributionManagement>...</project>

3)还可以配置分发类别 :发布版releases和快照版snapshots

<project>...<version>1.0.0-SNAPSHOT</version>...</project>

2.nexus3x上传第三方jar
在网上搜了很多,但是目前只找到命令行的方式

# nexus上传第三方jar #需要注意的是jar不能位于本地仓库中mvn deploy:deploy-file -DgroupId=org.springframework.boot -DartifactId=spring-boot   -Dversion=1.1.6.RELEASE  -Dpackaging=jar   -Dfile=D:\1.1.6.RELEASE\spring-boot-1.1.6.RELEASE.jar  -Durl=http://localhost:8088/repository/3rdpart/  -DrepositoryId=3rdpart

3.完成以上配置已经可以愉快的使用私服管理依赖、分发打包了。下面说说在idea中更便捷的操作:引入maven打包插件,实现一键打包分发

<project>...<plugins>  <plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-war-plugin</artifactId>    <version>2.4</version>  </plugin></plugins>...</project>

这里写图片描述
分发成功
这里写图片描述
这里写图片描述

四.管理依赖

1.通过私服引入jar
1)配置profiles的repositories和pluginRepositories(一般可写在maven的parent项目中,但公司多个项目可能就重复写配置了,所以这里写在maven的全局配置文件中。子项目也可以定义仓库,优先级大于公共仓库)

<settings>...<profiles>  <profile>    <id>nexus</id>    <repositories>      <repository>        <id>central</id>        <name>central</name>        <url>http://localhost:8088/nexus/content/groups/public</url>        <layout>default</layout>        <releases>          <enabled>true</enabled>        </releases>        <snapshots>          <enabled>true</enabled>        </snapshots>      </repository>    </repositories>    <pluginRepositories>      <pluginRepository>        <id>nexus</id>        <name>Nexus</name>        <url>http://localhost:8088/content/groups/public/</url>        <releases>          <enabled>true</enabled>        </releases>        <snapshots>          <enabled>true</enabled>        </snapshots>      </pluginRepository>    </pluginRepositories>  </profile><!--激活指定上述配置--><activeProfiles>  <activeProfile>nexus</activeProfile></activeProfiles>...</settings>

2)配置mirrors:
mirrors本质上是拦截器。
拦截mirrorOf指定的仓库访问,将其指向这里的地址。
mirrorOf可以指定具体的仓库id也可以是则拦截所有远程仓库的访问,强制指向指定私服。
由于镜像是地址重定向,其他如 属性还是以上面第一步的配置为准,当mirrorOf指定时,其余远程仓库配置将生效。

<mirrors>  <mirror>    <id>nexus</id>    <mirrorOf>*</mirrorOf>    <url>http://localhost:8088/repository/maven-public/</url>  </mirror></mirrors>
0 0