07 maven私服 nexus

我要很无聊的说说怎么找到这个东东来下载的
1. 官方网站

https://www.sonatype.com/

2. 找到get nexus

Paste_Image.png

3. 找到免费版本下载(免费试用肯定是收费的)

Paste_Image.png
Paste_Image.png

4. 启动cmd命令
(1)输入nexus:将提示 以下几种命令;
(2)nexus install 安装服务
(3)nexus start 启动服务

5. 访问 http://localhost:8081/nexus/
右上角 用户登录,默认的用户名和密码:admin/admin123

6. 仓库类型

Paste_Image.png
  • group:
    可以把其他的仓库加入到一个组中,就样我们关联一个组就可以关联到若干仓库
  • proxy:
    代理仓库,当我们本地没有对应的资源的时,会通过类型仓库去远程仓库(外网)下载,这里Apache Snapshots专门用来下载apache的资源
  • hosted:
    我们发布的模块会被提交到hosted类型的仓库,这样就能被组内其他成员依赖到我们的模块; 如果我们模块pom中的版本含有snapshot字样就表明这是一个快照模块,那么发布时会被提交到Snapshots仓库中

<version>0.0.1-SNAPSHOT</version>

7. 仓库配置
我们代理仓库的资源是通过索引来让我们找到的,所以我们要打开代理仓库的索引,并且配置代理仓库的远程下载地址
推荐:http://maven.aliyun.com/nexus/content/groups/public/

Paste_Image.png
Paste_Image.png

8. 使用私服
私服搭好了之后,我们需要在项目使用该私服了

1. 在根模块的pom中配置

    <repositories>
        <repository>
            <id>nexus</id>
            <name>nexus repository</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <!-- 为什么要开启快照呢? 因为group中包含了我们模块上传的仓库,而我们上传的模块又是snapshots类型的,所以需要开启 -->
        </repository>
    </repositories>

这是在项目中去设置,也就是说不同的项目都需要这样去配置,好像有点麻烦;我们知道每个maven项目使用的maven肯定都是一样的,那么我们可以去修改maven的配置文件呀

2. 在maven配置文件(settings.xml)中配置

    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <name>internal nexus repository</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>

这里贫僧要提个醒,最好看看eclipse中maven的配置,之前被坑惨了

Paste_Image.png

9. 流程图

Paste_Image.png

10. 发布项目到私服
1. 根模块pom中配置
选择要发布到的仓库

    <distributionManagement>
        <repository>
            <id>helloweb-release</id>
            <name>helloweb release resp</name>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>

        <snapshotRepository>
            <id>helloweb-snapshot</id>
            <name>helloweb snapshot resp</name>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

2. maven配置文件中配置
私服的仓库是有权限的,需要配置对应的用户名和密码

    <servers>
        <server>
            <id>helloweb-release</id><!-- 对应distributionManagement中配置的id -->
            <username>deployment</username><!-- 默认的用户名和密码 -->
            <password>deployment123</password>
        </server>
        
        <server>
            <id>helloweb-snapshot</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>

3. 补充
这只是将项目发现到了默认的仓库,其实我们可以针对不同的项目仓库不同的仓库,这些就日后再记录吧

具体教程请看或百度
http://blog.csdn.net/tutftn/article/details/51771800
http://www.cnblogs.com/demingblog/p/3840174.html

关于snapshot 和 release版本的问题
http://www.mzone.cc/article/277.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容