下载nexus

官方下载链接: https://help.sonatype.com/repomanager3/download/
笔者版本百度云:
链接:https://pan.baidu.com/s/1OBv24XGNlJzXOZdqTVnXTQ
提取码:1234
如果网络不好的话可以使用将该链接复制进迅雷下载,
maven私服搭建_xml文件

配置、启动,一步到位

解压后得到文件

nexus-3.29.0-02-unix.tar.gz

maven私服搭建_maven_02

进入sonatype下的配置文件夹配置

刚开始,sonatype-work目录下是没有etc文件夹的,启动过一次过后就会复制一份基础配置过来,
maven私服搭建_目录配置_03
启动关闭nexus

/app/nexus/nexus-3.29.0-02/bin/nexus start
/app/nexus/nexus-3.29.0-02/bin/nexus stop

maven私服搭建_目录配置_04
进入sonatype-work/etc工作目录配置

# 进入sonatype-work/etc工作目录配置
cd ./sonatype-work/nexus3/etc/
# 修改端口,也只要修改下端口注意别与已使用端口冲突就行,其余的全部采用默认配置就可以
vim nexus.properties

maven私服搭建_配置文件_05
maven私服搭建_xml文件_06

启动

# 返回nexus-3.29.0-02/bin/目录下启动
cd ../../../nexus-3.29.0-02/bin/
./nexus start

maven私服搭建_目录配置_07
此处顺便说一下,bin目录下的nexus.rc文件可以指定可以启动的用户,默认这个配置是关闭的,如果启动,则只有该配置的用户才能启动nexus
maven私服搭建_maven_08

访问nexus、开始基础配置

  1. 点击登录,告诉我们admin用户的密码存放位置,

maven私服搭建_目录配置_09
cat该文件获取密码

cat /app/nexus/sonatype-work/nexus3/admin.password

maven私服搭建_配置文件_10

  1. 输入密码,点击下一步,输入新密码,

maven私服搭建_maven_11

3.Configure Anonymous Access 配置匿名访问

由于我们的本意是搭建私服,是给自己内部使用的,所以这里必须配置成需要账号验证才行

maven私服搭建_目录配置_12
4. 私服仓库基础配置,由于默认是已经配置好了仓库的就不新增了,直接改下配置就用
maven私服搭建_配置文件_13
maven私服搭建_xml文件_14

至此,maven服务器的配置就基本完成,下面开始使用私服

配置本地maven

基础的maven安装由于太过简单这里就不说了,就算没有本地安装maven,使用idea的maven依赖也可以自动依赖安装maven,就是刚开时下载的时候稍微慢了一点点罢了。

发布jar包

只需要配置下maven项目的pom.xml即可

    <distributionManagement>
        <!--配置线上releases仓库地址,只要是正式版本都会上传到该地址(注意要和settings.xml文件里面的配置名称相同)-->
        <repository>
        	<!--仓库id-->
            <id>releases</id>
            <url>http://119.3.218.207:8082/repository/maven-releases/</url>
        </repository>
        <!--单纯使用的话,快照地址也可以不用配置-->
        <!--配置线上Snapshots仓库地址,只要是快照版本都会上传到该地址(注意要和settings.xml文件里面的配置名称相同)-->
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://119.3.218.207:8082/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

修改idea集成maven的配置文件

  • 在servers里面添加server
		<!--添加server-->
        <server>
        	<!--id即为上面的仓库id-->
            <id>releases</id>
            <username>admin</username>
            <password>*****</password>
        </server>
        <!--这里配置我们刚才创建的user用户所对应的Snapshots-->
        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>****</password>
        </server>
  • 在profiles添加profile(配置)
<profile>    
 <!--profile 的 id,需要在下面开启这个id--> 
   <id>tjsoft</id>    
	<repositories>    
	  <repository>
	  	<!--仓库id,对应上面的server配置里面的id-->
		<id>snapshots</id>
		<!--私服地址,该地址可以在nexus设置,仓库列表上点击url copy获取--> 
		<url>http://119.3.218.207:8082/repository/maven-releases/</url>
		<releases>    
		  <enabled>true</enabled>
		</releases>
		<snapshots>    
		  <enabled>true</enabled>    
		</snapshots>    
	  </repository>    
	</repositories>
 </profile>
  • 启动配置
 <activeProfiles> 
	<activeProfile>tjsoft</activeProfile>
 </activeProfiles> 

至此,所有配置均已完成,直接使用即可
maven私服搭建_xml文件_15

遇到过的问题
401,未认证,检查server配置的密码是否正确,检查server的id与配置的仓库id是否一致