安装maven私服Nexus3
预置条件
- Java环境
- Maven环境
- nexus安装包
打开解压目录:
-> nexus-3.32.0-03 安装目录
..... 主要文件夹
-> bin 命令文件目录
-> etc 配置文件目录
-> sonatype-work 工作目录
# 进入文件bin目录
nexus-3.32.0-03 -> cd ./nexus-3.32.0-03/bin
# 运行nexus
bin -> ./nexus run
访问网址
http://localhost:8081/
登录账号密码,在安装文件目录下
配置nexus3
找到安装根目录: /apache-latest-nexus-3.32/nexus-3.32.0-03/etc
修改 nexus-default.properties
仓库名 | 作用 |
---|---|
hosted 宿主仓库 | 要用于部署无法从公共仓库获取的构件以及自己或第三方的项目构件(存放本公司开发的jar包(正式版本、测试版本)) |
proxy 代理仓库 | 代理公共的远程仓库 |
group 仓库组 | Nexus 通过仓库组统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库(使用时连接组仓库,包含Hosted(宿主仓库)和Proxy(代理仓库)) |
release仓库 | 内部的模块中release模块的发布仓库 |
snapshots | 发布那些非release版本, 非稳定版本 |
替换nexus远程仓库地址
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-k3TuXGmf-1645232709078)(/Users/zwl/Library/Application Support/typora-user-images/image-20211109102026379.png)]
上传本地项目骨架到私服
-
新建项目
-
引入maven骨架插件
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-archetype-plugin</artifactId> <version>3.2.0</version> </plugin>
-
执行创建Maven模板命令
在项目下pox.xml目录下执行下面命令
mvn archetype:create-from-project
-
进入当前目录生成的文件夹,在执行install
cd target\generated-sources\archetype mvn install ##生成到本地的repository中,在repository文件夹中的archetype-catalog.xml中
-
在生成的pom.xml文件中添加私服的地址
<distributionManagement> <repository> <id>releases</id> <!-- 自定义releases版的id id要和setting文件中server的ID对应--> <name>Nexus Release Repository</name> <url>http://XXXX/repository/maven-releases/</url> <!-- 私服中releases的仓库地址 --> </repository> <snapshotRepository> <id>snapshots</id> <!-- 自定义snapshots版的id id要和setting文件中server的ID对应--> <name>Nexus Snapshot Repository</name> <url>http://xxx/repository/maven-snapshots/</url> <!-- 私服中snapshots的仓库地址 --> </snapshotRepository> </distributionManagement>
-
配置本地setting文件
<servers> <server> <id>releases</id> <username>admin</username> <password>admin</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin</password> </server> </servers>
## 检查本地setting.xml配置是否有错误 mvn help:effective-settings
-
项目上传
在第4步的目录中执行如下命令即可
mvn deploy
从私服中下载项目骨架
-
在setting.xml中配置镜像的地址
<mirror> <id>Nexus-aliyun</id> <!-- 关于mirrorOf,如果有同名的mirrorOf,那么只会匹配第一个,如果有<mirrorOf>*</mirrorOf>,优先匹配名字完全相同的,其次匹配通配符 --> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>https://maven.aliyun.com/repository/central</url> </mirror>
</profiles> <profile> <id>nexus-mr</id> <repositories> <!-- 配置的顺序决定了下载 jar 包的顺序 --> <!-- maven下载时,按顺序查找,优先找nexus,找不到再找central --> <!-- 这里nexus为我的私服地址 --> <repository> <id>nexus</id> <url>http://XXX/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <!-- 中央仓库此处可省略 --> <repository> <id>central</id> <url>https://maven.aliyun.com/repository/central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://XXX/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> <pluginRepository> <id>central</id> <url>https://maven.aliyun.com/repository/central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus-mr</activeProfile> </activeProfiles>
- 在IDEA中添加私服中的项目