mac安装nexus3.28私服并进行maven相应配置
CSDN下载链接:nexus3.28全平台下载(mac,linux,windows)
百度网盘链接:nexus3.28全平台下载(mac,linux,windows) 提取码: xdkv
windows 安装nexus并配置可参考:
https://blog.csdn.net/weixin_44190513/article/details/111162932
Linux 安装nexus并配置可以参考:
https://blog.csdn.net/weixin_44798288/article/details/111560131
安装环境
java -version 1.8.0_311
mvn-v Apache Maven 3.8.3
切换到nexus/bin安装目录下执行
可以在nexus/etc/nexus-default.properties进行配置
#启动nexus
./nexus start
#停止nexus
./nexus stop
运行后稍等一下可以进入页面:localhost:8081/nexus
点击Sign In根据提示找到密码所在地,并完成修改密码操作,admin为用户名
Repositories介绍
maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
maven-releases:私库发行版jar,公司或团队内部的包,正式版。
maven-snapshots:私库快照(调试版本)jar,公司或团队内部的包,开发测试版。
maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。它的目的就是把多个仓库组合起来,然后我们项目中只需要配置上这个类型的仓库地址,就可以把它里面组合的几个仓库都关联上。
进行maven 下settings.xml配置:
(注:.m2/repository下的settings.xml可以不用进行配置)
<?xml version="1.0" encoding="UTF-8"?>
<!-- defaultSetting -->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<!-- iSetting -->
<localRepository>/Users/yirenkeji8/.m2/repository</localRepository>
<!-- defaultSetting -->
<pluginGroups></pluginGroups>
<!-- defaultSetting -->
<proxies></proxies>
<!-- defaultSetting -->
<servers>
<!-- iSetting -->
<!-- 在setting.xml中的servers配置认证信息。-->
<server>
<id>nexus_release</id>
<username>admin</username>
<password>admin123456</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
<server>
<id>nexus_snapshots</id>
<username>admin</username>
<password>admin123456</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
<server>
<id>central-proxy</id>
<username>admin</username>
<password>admin123456</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
<!-- defaultSetting -->
<mirrors>
<!-- defaultSetting -->
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
<!-- iSetting -->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/repository/maven-public/</url>
</mirror>
<mirror>
<id>alimaven</id>
<mirrorOf>*</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<!-- defaultSetting -->
<profiles>
<!-- iSetting -->
<profile>
<id>nexus</id><!--和activeProfile 值一致 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8081/mexus/repository/maven-central/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
<enabled>true</enabled>
<!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。 -->
<updatePolicy>never</updatePolicy>
<!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。 -->
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<!--用于定位和排序构件的仓库布局类型-可以是default(默认)或者legacy(遗留)。Maven 2为其仓库提供了一个默认的布局;然而,Maven 1.x有一种不同的布局。我们可以使用该元素指定布局是default(默认)还是legacy(遗留)。 -->
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://localhost:8081/nexus/repository/maven-central/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活上面配置的仓库信息-->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
添加阿里云仓库
添加阿里云仓库就是为了在私服找不到依赖包时能去阿里云找,找到后返回给依赖方并缓存到私服。
选择maven2(proxy)
改图中两个地方即可,一个是资源名字,一个是远程仓库地址,这里我们输入http://maven.aliyun.com/nexus/content/groups/public/作为远程仓库地址。然后点击下方Create repository。
设置maven-public设置添加并置顶之前的添加配置的私服仓库地址,点击下方的Save按钮
在项目中使用
获取依赖包
如果是普通项目成员,不需要向私服发布包的,只需要在 pom 文件中加入以下配置即可。
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://localhost:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>