为何要在本地开发机器上安装nexus?首先声明公司内部是有本身的nexus仓库,可是对上传jar包作了限制,不能畅快的上传本身测试包依赖。因而就本身在本地搭建了一个nexus私服,便可以使用公司nexus私服仓库中的依赖,也能够上传和使用本身的测试包依赖。app
Download Nexus Repository OSSmaven
将下载的nexus-3.14.0-04-win64.zip解压到自定义目录便可。测试
打开zip解压文件下的 ../nexus-3.14.0-04-win64/nexus-3.14.0-04/etc/nexus-default.properties。
以下属性能够自定义修改。gradle
一般能够不作任何修改,但我的习惯于修改 application-host 为127.0.0.1(关于0.0.0.0与127.0.0.1的区别自行检索),我这里只修改了端口。url
在.../nexus-3.14.0-04-win64/nexus-3.14.0-04/bin 目录下,以管理员身份运行cmd
1. nexus.exe /run 命令能够启动nexus服务(参考官方文档)
2. 安装nexus本地服务来启动(推荐使用这种方式,参考官方文档),命令以下所示。spa
nexus.exe /install <optional-service-name> //安装nexus服务 nexus.exe /install <optional-service-name> //安装nexus服务
nexus.exe /start <optional-service-name> //启动nexus服务 nexus.exe /stop <optional-service-name> //中止nexus服务
默认的用户名和密码分别是:admin/amdin123代理
若是没有作任何端口和上下文路径的修改,直接访问 http://localhost:8081便可。code
仓库名
|
做用
|
hosted(宿主仓库库)
|
存放本公司开发的jar包(正式版本、测试版本)
|
proxy(代理仓库)
|
代理中央仓库、Apache下测试版本的jar包
|
group(组仓库)
|
使用时链接组仓库,包含Hosted(宿主仓库)和Proxy(代理仓库)
|
virtual (虚拟仓库)
|
基本用不到,重点关注上面三个仓库的使用
|
如上图所示,maven-public就我建立的组仓库。以及还建立了3个代理仓库,以下。server
一、jcenter仓库:https://jcenter.bintray.com/xml
二、maven中央仓库:https://repo1.maven.org/maven2/
三、公司内部nexus仓库,这里就不给出了
最后创建组仓库maven-public,以下。
组仓库中包含了公司私服、jcenter、maven-central、本地maven-releases,本地maven-snapshots。
建立好组仓库以后,修改setting.xml文件,添加maven仓库镜像,以下。
<server> <id>local</id> <username>hjzgg</username> <password>hjzgg</password> </server> <mirror> <id>local</id> <mirrorOf>central</mirrorOf> <name>localhost nexus</name> <url>http://localhost:8082/repository/maven-public/</url> </mirror>
接着修改maven项目中的pom.xml,以下。
<distributionManagement> <repository> <id>maven-releases</id> <name>Nexus Release Repository</name> <url>http://localhost:8082/repository/maven-releases/</url> </repository> <snapshotRepository> <id>maven-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:8082/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
若是是gradle项目,修改init.gradle文件,以下。
uploadArchives {
def nexus_credentials = [userName: "hjzgg", password: "hjzgg"]
repositories.mavenDeployer {
snapshotRepository(url: "http://127.0.0.1:8082/repository/maven-snapshots/") {
authentication(nexus_credentials)
}
repository(url: "http://127.0.0.1:8082/repository/maven-releases/") {
authentication(nexus_credentials)
}
}
}
请参考:订阅号文章nexus安装和配置