本地使用nexus3.18.1 repository manager搭建maven私服及使用

maven私服搭建nexus3.18.1
1、安装nexus
2、安装私服
3、配置阿里云镜像
1、安装nexus
1.1 进入nexus解压目录后,打开cmd, 注册nexus服务

    nexus.exe  /install nexus
1
1.2 启动nexus服务

nexus.exe /start nexus
1
现在,就可以访问localhost:8081,登录管理页面了。
1.3 登录
以前版本的nexus,默认登录账号是:admin,密码:admin123
不过我登录时,却发现密码错误

仔细看提示,告诉你admin账户的密码在sonatype-work\nexus3下边的admin.password文件中,根据提示路径打开这个文件即可看到一长串密码,这样就能登录了。
瞧瞧,登录后的界面和原来也不一样了,初始生成的仓库都和nexus2不太一样


看来nexus3之后考虑到安全性,登录密码改成随机生成的了,而且登录成功后会引导你修改admin账号的密码,安全感满屏有木有。。。

2、安装私服
安装私服前,可是看了不少文档,归根到底主要就是2件事儿:

2.1 在settign.xml(针对全局)或者具体某个pom.xml(针对具体的项目)文件中配置仓库的信息
仅以setting.xml文件中配置为例:
id: 就是每个repository的唯一标识,其实就是name

name:这个个性化配置吧
url:图中URL列下边有很多copy,点击就能看到。

<profiles>
  <profile>
        <id>myProfile</id>
        <repositories>
            <repository>
                <id>maven-public</id>
                <name>Repository for me</name>
                <url>http://localhost:8081/repository/maven-public/</url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>maven-public</id>
                <name>PluginRepository for me</name>
                <url>http://localhost:8081/repository/maven-public/</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>
  </profiles>
   <!--使用profile定义仓库需要激活才可生效-->  
  <activeProfiles>  
   <activeProfile>myProfile</activeProfile>  
 </activeProfiles>  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2.2 如果需要上传jar包到私服,还要进行权限校验,这个也非常简单
2.2.1 在setting.xml中配置server
记住这个id,在这儿使用账号密码进行了校验,在pom.xml中配置上传到哪个仓库时,要用到这个id

<servers>
    <server>
      <id>snapshotRepo</id>
      <username>nexus中配置的用户名,也可以直接用admin</username>
      <password>对应账户的密码</password>
    </server>
    <server>
      <id>releaseRepo</id>
      <username>admin</username>
      <password>admin密码</password>
    </server>
    </servers>
1
2
3
4
5
6
7
8
9
10
11
12
2.2.2 在pom.xml中配置distributionManagement
看到了吧,id就是server的id,两处配置通过这个id关联起来了。
name:个性化吧
url:还是仓库中URL那一列的值,注意上传类型snapshot和release分别对应各自的仓库

<distributionManagement>
        <snapshotRepository>
            <id>snapshotRepo</id>
            <name>maven-snapshots</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
        <!--<repository>
            <id>releaseRepo</id>
            <name>maven-release</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </repository>-->
    </distributionManagement>
1
2
3
4
5
6
7
8
9
10
11
12
3、配置阿里云镜像
在setting.xml文件中增加:

<mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun  Mirror</name>
      <mirrorOf>central</mirrorOf>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>  
  </mirrors>
1
2
3
4
5
6
7
8
让maven飞起来吧!
————————————————
版权声明:本文为CSDN博主「梦回大唐2019」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42428528/article/details/100776877

发布了51 篇原创文章 · 获赞 80 · 访问量 93万+

猜你喜欢

转载自blog.csdn.net/xiyang_1990/article/details/104221470