一,部署Nexus
首先是先部署Nexus 我这里就不讲解了按照官网来就可以。
二,Nexus仓库类型说明
1)group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;
2)hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);
3)proxy(代理类型):从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);
4)virtual(虚拟类型):虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用)
三,创建仓库
点击上方的设置按钮到Repository->Repositores->Create repository
1,第一个创建的是maven2(proxy) (类似于远程中央仓库)
proxy 这里就是代理的意思,代理中央Maven仓库,当PC访问中央库的时候,先通过Proxy下载到Nexus仓库,然后再从Nexus仓库下载到PC本地。
这样的优势只要其中一个人从中央库下来了,以后大家都是从Nexus私服上进行下来,私服一般部署在内网,这样大大节约的宽带。
Name: 代理名称-根据自己的业务和项目来规定名称
Remote storage: 代理仓库这里使用阿里云的 https://maven.aliyun.com/repository/public
其他的可以先默认
2,第二个创建maven2(hosted)
Hosted是宿主机的意思,本地存储。像官方仓库一样提供本地私库功能 把第三方的Jar放到私服上。
Hosted有三种方式,Releases、SNAPSHOT、Mixed
Releases: 一般是已经发布的Jar包
Snapshot: 未发布的版本
Mixed:混合的
Hosted的创建和Proxy是一致的,具体步骤和上面基本一致。如下:
Name: 宿主机的名称
Deployment pollcy: 部署策略 我们这里要用Allow redeploy
Security: 这里主要是用户、角色、权限的配置
其他默认即可
3,第三个创建maven2(group)
hosted本地仓库在前,远程仓库在后
四,配置settings.xml文件
nexus-releases admin xxxx nexus-snapshots admin xxxx
id: 这里预先定义,后面会对应上的
username: 登录nexus的账号
password: 登录nexus的密码
nexus-releases * http://xxxxxxx/repository/contract-maven-hosted/ nexus-snapshots * http://xxxxxxx/repository/contract-maven-public/
id: 和前面定义的对应上 被用来区分mirror元素
mirrorOf: 镜像所包含的仓库的Id。例如,指向Maven central仓库的镜像(http://repo1.maven.org/maven2/),设置这个元素为central。更多的高级映射例如repo1,repo2 或者*,!inhouse都是可以的。没必要一定和mirror的id相匹配。在这里mirrorOf项当然应该使用*,以表明是所有仓库都会被镜像到指定的地址。
url: 镜像基本的URL,构建系统将使用这个URL来连接仓库。这里应该添nexus仓库的地址,地址可以在nexus仓库页面中找到。(在Browse页面copy按钮中)
nexus nexus-releases http://xxxxxxxxxx/repository/contract-maven-hosted/ true true nexus-snapshots http://xxxxxxxxxx/repository/contract-maven-public/ true true nexus-releases http://xxxxxxxxxx/repository/contract-maven-hosted/ true true nexus-snapshots http://xxxxxxxxxx/repository/contract-maven-public/ true true
id: 用来确定该profile的唯一标识。
repositories/repository: 用以规定依赖包仓库的相关信息。在下属节点中,id和上面定义的进行对应;URL是指仓库地址,releases和snapshots放在一块说吧,这两个节点下属的enable节点用以规定对应的依赖包是否对当前策略有效,假如将snapshot的enable项设为disable,则不会下载snapshot包。
pluginRepositories/pluginRepository: 用以规定插件仓库的相关信息。其下属节点与repository的相同。
nexus
启用当前配置 用以规定当前启用的配置,将对应profile的ID加入到这一项即可使profile生效。
完整配置
D:mavenapache-maven-3.6.0-binapache-maven-3.6.0rogo nexus-releases admin xxxxxxxxxx nexus-snapshots admin xxxxxxxxxx nexus-releases * http://xxxxxxxxxx/repository/contract-maven-hosted/ nexus-snapshots * http://xxxxxxxxxx/repository/contract-maven-public/ nexus nexus-releases http://xxxxxxxxxx/repository/contract-maven-hosted/ true true nexus-snapshots http://xxxxxxxxxx/repository/contract-maven-public/ true true nexus-releases http://xxxxxxxxxx/repository/contract-maven-hosted/ true true nexus-snapshots http://xxxxxxxxxx/repository/contract-maven-public/ true true nexus
上传jar包到仓库
在Upload->找到我们事先创建的hosted
填写值就可以,最后把Generate a POM file with these coordinates给勾上。
pom.xml
io.transwarp stellarjdbc-driver 1.6.6
最后分享一个错误 Caused by: java.lang.IllegalStateException: Zip64 archives are not supported
网上说是因为导入的jar包过大导致的错误,需要在pom.xml文件里面build->plugins标签下shade插件的配置
org.apache.maven.plugins maven-shade-plugin org.springframework.boot spring-boot-maven-plugin 2.1.1.RELEASE true true *:* meta-INF/*.SF meta-INF/*.DSA meta-INF/*.RSA package shade meta-INF/spring.handlers meta-INF/spring.factories meta-INF/spring.schemas com.contract.ContractApplication ${project.artifactId}
注意:Main-Class填写自己项目的启动类即可



