拓展浏览
maven 包治理平台-01-maven 入门介绍 + Maven、Gradle、Ant、Ivy、Bazel 和 SBT 的具体比照表格
maven 包治理平台-02-windows 装置配置 + mac 装置配置
maven 包治理平台-03-maven project maven 我的项目的创立入门
maven 包治理平台-04-maven archetype 我的项目原型
maven 包治理平台-05-multi module 多模块
maven 包治理平台-06-罕用技巧 实时更新快照/乱码问题/下载很慢/包依赖解决包抵触/如何导入本地 jar
maven 包治理平台-07-plugins 常见插件介绍
maven 包治理平台-08-nexus 本人搭建 maven 仓库
Nexus
Nexus 是组织、存储和散发软件组件的最佳形式。
下载
下载
装置办法:
- 蕴含Jetty的捆绑包,只需 JRE。我抉择了这种形式
nexus-2.13.0-01-bundle.tar.gz
; - War,能够部署在Web上。
装置
将文件解压到所需地位。蕴含两个文件夹:
- nexus-2.13.0-01 蕴含Nexus运行所需的内容。
- sonatype-work 蕴含配置、仓库、日志文件。
启动
进入 bin 文件夹,在 ~/nexus-2.13.0-01/bin
中运行 nexus,您可能会失去:
houbinbindeMacBook-Pro:~ houbinbin$ /Users/houbinbin/IT/learn/nexus/nexus-2.13.0-01-bundle/nexus-2.13.0-01/bin/nexus ; exit;Usage: /Users/houbinbin/IT/learn/nexus/nexus-2.13.0-01-bundle/nexus-2.13.0-01/bin/nexus { console | start | stop | restart | status | dump }logoutSaving session......copying shared history......saving history...truncating history files......completed.
因而,只需运行以下命令即可启动 Nexus 服务器。
/Users/houbinbin/IT/learn/nexus/nexus-2.13.0-01-bundle/nexus-2.13.0-01/bin/nexus start
您能够在以下门路的文件 nexus.properties
中编辑 端口:
~/nexus/nexus-2.13.0-01-bundle/nexus-2.13.0-01/conf
拜访
在浏览器中输出URL,而后您能够拜访 Nexus 的仪表板。
http://127.0.0.1:8081/nexus
您能够在右上角登录 Nexus,默认管理员是:
用户名:admin明码:admin123
Config
在 setting.xml
中设置所有近程仓库应用外部仓库。
<!--setting maven only use internal repository--><mirrors> <mirror> <id>central</id> <name>central-mirror</name> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public/</url> </mirror></mirrors><profiles> <profile> <!--this profile will allow snapshots to be searched when activated--> <id>public-snapshots</id> <repositories> <repository> <id>public-snapshots</id> <url>http://localhost:8081/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public-snapshots</id> <url>http://localhost:8081/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile></profiles><activeProfiles> <activeProfile>public-snapshots</activeProfile></activeProfiles>
Repository
Remote Repository
- 在 pom.xml 中设置
<repositories> <repository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://localhost:8081/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots> <enabled>true</enabled> <checksumPolicy>ignore</checksumPolicy> <updatePolicy>daily</updatePolicy> </snapshots> </repository></repositories>
- 在 setting.xml 设置认证信息
<settings> <!--...--> <servers> <server> <id>my-auth</id> <username>usr</username> <password>pwd</password> </server> </servers></settings>
在 setting.xml
中必须有一个 server,它的 id 与 pom.xml
中的雷同,并且正确配置认证信息。
在 pom.xml
中将我的项目部署到近程仓库。
<distributionManagement> <repository> <id>releases</id> <name>Nexus Releases Repository</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshots Repository</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository></distributionManagement>
而后,应用以下命令能够部署它:
mvn clean deploy
在部署时须要进行身份验证。
<servers> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server></servers>
默认角色:
1) admin :对 Nexus 服务的齐全管制权限,默认明码为 admin123
2) deployment :可能拜访 Nexus ,浏览仓库内容,搜寻并且上传部署构件但无奈配置 Nexus ,默认明码为: deployment123
3) anonymous :对应所有未登录用户,能够浏览和搜寻仓库
Jar包存储地址默认为:
~/nexus/nexus-2.13.0-01-bundle/sonatype-work/nexus/storage
镜像
从 X 仓库获取的所有内容,也能够从它的镜像获取。
实际上我喜爱这样配置:
<mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public</url> </mirror></mirrors>
<mirrorOf>*</mirrorOf>
匹配所有近程仓库。<mirrorOf>external: *</mirrorOf>
匹配所有非本地主机的近程仓库。<mirrorOf>repo1, repo2</mirrorOf>
匹配 repo1 和 repo2...<mirrorOf>*, !repo1</mirrorOf>
匹配所有仓库,但不包含 repo1。
注: 这个个别不必批改。
Tips
- Cannot deploy artifacts when Maven is in offline mode
- 上传三方jar到 nexus
点击【Add Artifact】-》点击【Upload Artifact(s)】
参考资料
intro zh_CN
3rd zh_CN
setting zh_CN
本文由博客一文多发平台 OpenWrite 公布!