使用nexus搭建maven私服、发布项目及引用项目
使用nexus搭建maven私服
作用:内网开发,项目共享
安装和启动
- 服务的安装、卸载、启动和关闭
- 若安装或启动时出现错误:wrapper | The nexus service was launched, but failed to start.
解决:- 将jdk版本换为jdk8或jdk7;
- 打开nexus-2.12.0-01\bin\jsw\conf\wrapper.conf,搜索wrapper.java.command并设置为java.exe的绝对路径,如下图。
修改端口
- 设置nexus-2.12.0-01\conf\nexus.properties中“application-port”值,如 application-port=8091
- 注意修改后重启服务才生效。
访问:http://localhost:8091/nexus
登录:账户-admin 密码-admin123
添加Central库离线索引(用于搜索)
-
远程下载(建议):将同步远程仓库索引设置为true;2GB左右,访问外网,下载很慢
-
离线拷贝:将下载好的Central离线索引库直接拷贝到“nexus\sonatype-work\nexus\indexer\central-ctx”目录下,原来的文件直接清除
配置maven连接私服
- maven的配置文件是conf/setting.xml
- maven的基本使用需要配置:
① 本地仓库路径
② 远程仓库路径
③ JDK版本 - maven连接私服相对于基本使用需要增加如下配置:
① 将远程仓库路径修改为私服仓库路径
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8091/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8091/nexus/content/repositories/apache-snapshots/</url>
</mirror>
② 配置nexusTest并激活
<!--配置nexusTest:添加到<profiles>标签内部-->
<profile>
<id>nexusTest</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://127.0.0.1:8091/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<!--激活nexusTest:添加到根节点<settings>下面-->
<activeProfiles> <!--激活id为nexusTest的profile-->
<activeProfile>nexusTest</activeProfile>
</activeProfiles>
发布项目到私服和引用私服中的项目
项目的pom.xml文件中添加releases和snapshots的Summary
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8091/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8091/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
在maven配置文件conf/setting.xml的servers下配置releases和snapshots的账户和密码
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
发布项目到私服
-
IDEA发布
-
发布到releases仓库下还是snapshots仓库下与项目version有关
引用私服中的项目
- 在项目的pom.xml中添加相应的项目依赖即可