Nexus 一般用来搭建位于组织或公司内部的 Maven 私服,代理所有的仓库(包括中央仓库),用户通过它就可以获取和管理所有所需的 Maven 构件。
二、Nexus3搭建安装
1、下载地址
https://help.sonatype.com/repomanager3/product-information/download
2、解压
tar -zxvf nexus-3.43.0-01-unix.tar.gz
nexus-3.43.0-01:nexus安装目录,服务目录
sonatype-work:数据目录,是真正的仓库
3、修改配置文件
cd /home/nexus/nexus-3.43.0-01/etc
vim nexus-default.properties
##默认端口8081,修改访问端口,不修改也没关系
application-port=18081
4、启动
cd /home/nexus/nexus-3.43.0-01/bin
./nexus start
5、访问web页面
http://localhost:18081/ (不修改配置文件,默认端口为8081)
初始账号 admin,初始密码保存在nexus安装目录下的 sonatype-work 的 admin.password 文件中,进去之后按提示修改
三、创建公司私服
1、proxy:代理仓库,设置阿里云等中心仓库
阿里云地址:https://maven.aliyun.com/nexus/content/groups/public/
2、host:本地仓库
- 有Release(稳定版)、Snapshot(快照版)、Mixed(混合版)三种
- Deployment policy :Disable redeploy(仓库包禁止重新deploy),Allow redeploy(仓库包允许重新deploy)
3、group:提供对外的统一的仓库
4、构建结果
四、页面上传jar
五、idea上传jar
1、maven settings文件配置
配置上述步骤中自定义的host私库,如果项目version以 SNAPSHOT结尾,上传到快照库,否则上传到稳定库
<servers>
<server>
<id>xxx-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>xxx-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
2、idea pom文件配置
id必须也settings文件server id一样
<distributionManagement>
<repository>
<id>xxx-releases</id>
<url>http://ip:port/repository/xxx-releases/</url>
<name>xxx-releases</name>
</repository>
<snapshotRepository>
<id>xxx-snapshots</id>
<url>http://ip:port/repository/xxx-snapshots/</url>
<name>xxx-snapshots</name>
</snapshotRepository>
</distributionManagement>
3、idea打包上传
注意:需要注释掉项目pom文件中springboot-maven-plugin插件,不然上传包会带有BOOT-INF目录,其他项目能下载该jar包,但无法引用jar包的类;或者使用
六、idea下载jar
1、maven settings文件配置
<servers>
<server>
<id>xxx-public</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<mirrors>
<mirror>
<id>xxx-public</id>
<name>xxx-public</name>
<url>http://ip:port/repository/xxx-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
七、注意问题
在idea打包上传jar时,项目版本号需要写具体版本号,不要用${xxx}方式引用,不然会导致jar虽然上传到私服了,但是其他项目在下载时会以${xxx}方式路径去下载,导致找不到对应jar。
总结
1、maven settings文件整体配置
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>F:\xxx\repository</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>xxx-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>xxx-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>xxx-public</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<mirrors>
<mirror>
<id>xxx-public</id>
<name>xxx-public</name>
<url>http://ip:port/repository/xxx-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
</settings>