搭建本地的nexus-maven-仓库

下载搭建的文件

下载地址

Paste_Image.png

找到合适的版本文件夹:

Paste_Image.png

修改配置文件

Paste_Image.png

wrapper.java.command=java 配置java的环境变量即可。

点击console-nexus.bat,运行服务器

Paste_Image.png
访问:http://localhost:8081/nexus

Paste_Image.png

右上角登陆,账号密码 admin,admin123

新建仓库

点击repositories

Paste_Image.png

内置的几个仓库说明:

  1. Releases:这里存放我们自己项目中发布的构建, 通常是Release版本的, 比如我们自己做了一个FTP Server的项目, 生成的构件为ftpserver.war, 我们就可以把这个构建发布到Nexus的Releases本地仓库. 关于符合发布后面会有介绍.

  2. Snapshots:这个仓库非常的有用, 它的目的是让我们可以发布那些非release版本, 非稳定版本, 比如我们在trunk下开发一个项目,在正式release之前你可能需要临时发布一个版本给你的同伴使用, 因为你的同伴正在依赖你的模块开发, 那么这个时候我们就可以发布Snapshot版本到这个仓库, 你的同伴就可以通过简单的命令来获取和使用这个临时版本.

  3. 3rd Party:顾名思义, 第三方库, 你可能会问不是有中央仓库来管理第三方库嘛,没错, 这里的是指可以让你添加自己的第三方库, 比如有些构件在中央仓库是不存在的. 比如你在中央仓库找不到Oracle 的JDBC驱动, 这个时候我们就需要自己添加到3rdparty仓库。

新建自己的仓库,可选好几种类型的仓库。

Paste_Image.png

  • hosted,本地仓库,通常我们会部署自己的构件到这一类型的仓库。比如公司的第二方库。
  • proxy,代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。
  • group,仓库组,用来合并多个hosted/proxy仓库,当你的项目希望在多个repository使用资源时就不需要多次引用了,只需要引用一个group即可。
  • virtual 虚拟仓库,用得少

使用新增的仓库

编写build.gradle文件:

group = 'com.mrzhang.andcomponent'
version = '0.0.3'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri('http://localhost:8081/nexus/content/repositories/TestDemo'))
                    {
                        authentication(userName: "admin", password: "admin123")
                    }
        }
    }
}

然后点击uploadArchives

Paste_Image.png

成功之后就能看到仓库里出现了:

Paste_Image.png

如何引用:
这是一个apply plugin插件,在根部引用:

Paste_Image.png

相关异常处理

Error:Execution failed for task ':build-gradle:uploadArchives'.
> Could not publish configuration 'archives'
   > Failed to deploy artifacts: Could not transfer artifact com.mrzhang.andcomponent:build-
gradle:jar:0.0.3 from/to remote (http://localhost:8081/nexus/content/repositories/TestDemo): 
Failed to transfer file: http://localhost:8081/nexus/content/repositories/TestDemo/com/mrzhang/andcomponent/build-
gradle/0.0.3/build-gradle-0.0.3.jar. Return code is: 400, ReasonPhrase: Bad Request.

发布版本冲突: 因为仓库已经有相同版本的jar包。
解决办法:
1.修改版本号:version = '0.0.1'
2.设置强制覆盖原来的jar包:

Paste_Image.png