最近学院搭服务器集群供大数据学习使用,平台上的Hadoop全家桶使用CDH来搭建,由于国内没有CDH版本的Maven依赖,负责搭集群的大佬在国外镜像拉了依赖下来,但是整个仓库打包又太麻烦,于是我来协助建一个私有仓库,方便学院的同学们使用
本文主要记录使用阿里云效来搭建Maven私有仓库期间所踩的坑
选用阿里云效来搭Maven私仓的原因是
阿里云效的官方文档(页面截图旧,不过勉强能搞懂怎么创建私仓),官方地址
有了私仓,我们就直接把本地仓库迁移到私仓了,按照如图所示官方的方法进行迁移:
坑: 本地仓库中,不能存在空目录,否则迁移会报错中止:
在按照官方的提示配置好Maven的配置(USER_HOME/.m2/settings.xml)后,可以正常deploy,但是还是无法下载私仓中的依赖,导致pom标红,在翻看官方文档和百度Maven私仓有关内容后仍然无果(上网查Maven私仓配置,跟官网的说明几乎无二)
在添加profiles节点后,应在配置文件的后面追加:
<activeProfiles>
<activeProfile>rdc-private-repoactiveProfile>
activeProfiles>
如果activeProfiles节点中没有你刚加入的profile节点的id,则该profile节点不会生效
官方示例配置中并没有提示用户添加mirrors节点,这也是只能deploy而不能从私仓中下载依赖的原因
在mirrors节点中,应追加如下mirror节点:
<mirror>
<id>rdc-releasesid>
<mirrorOf>rdc-releasesmirrorOf>
<name>rdc-releasesname>
<url>https://repo.rdc.aliyun.com/repository/你的releases私仓地址/url>
mirror>
<mirror>
<id>rdc-snapshotsid>
<url>https://repo.rdc.aliyun.com/repository/你的snapshots私仓地址/url>
<mirrorOf>rdc-snapshotsmirrorOf>
<name>rdc-snapshotsname>
mirror>
注意: 此处mirror
节点下的id
,应与server
节点下的id
对应
在这个问题上搞了半天,只能感叹自己的Maven基础还不扎实,菜了
USER_HOME/.m2/settings.xml配置如下:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>mirrorid>
<mirrorOf>central,jcentermirrorOf>
<name>mirrorname>
<url>https://maven.aliyun.com/nexus/content/groups/publicurl>
mirror>
<mirror>
<id>rdc-releasesid>
<mirrorOf>rdc-releasesmirrorOf>
<name>rdc-releasesname>
<url>https://repo.rdc.aliyun.com/repository/你的私仓release地址/url>
mirror>
<mirror>
<id>rdc-snapshotsid>
<url>https://repo.rdc.aliyun.com/repository/你的私仓snapshots地址/url>
<mirrorOf>rdc-snapshotsmirrorOf>
<name>rdc-snapshotsname>
mirror>
mirrors>
<servers>
<server>
<id>rdc-releasesid>
<username>你的用户名username>
<password>你的密码password>
server>
<server>
<id>rdc-snapshotsid>
<username>你的用户名username>
<password>你的密码password>
server>
servers>
<profiles>
<profile>
<id>rdcid>
<properties>
<altReleaseDeploymentRepository>
rdc-releases::default::https://repo.rdc.aliyun.com/repository/你的私仓release地址/
altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>
rdc-snapshots::default::https://repo.rdc.aliyun.com/repository/你的私仓snapshots地址/
altSnapshotDeploymentRepository>
properties>
<repositories>
<repository>
<id>centralid>
<url>https://maven.aliyun.com/nexus/content/groups/publicurl>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>falseenabled>
snapshots>
repository>
<repository>
<id>snapshotsid>
<url>https://maven.aliyun.com/nexus/content/groups/publicurl>
<releases>
<enabled>falseenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
<repository>
<id>rdc-releasesid>
<url>https://repo.rdc.aliyun.com/repository/你的私仓release地址url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>falseenabled>
snapshots>
repository>
<repository>
<id>rdc-snapshotsid>
<url>https://repo.rdc.aliyun.com/repository/你的私仓snapshots地址/url>
<releases>
<enabled>falseenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>centralid>
<url>https://maven.aliyun.com/nexus/content/groups/publicurl>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>falseenabled>
snapshots>
pluginRepository>
<pluginRepository>
<id>snapshotsid>
<url>https://maven.aliyun.com/nexus/content/groups/publicurl>
<releases>
<enabled>falseenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
<pluginRepository>
<id>rdc-releasesid>
<url>https://repo.rdc.aliyun.com/repository/你的私仓release地址url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>falseenabled>
snapshots>
pluginRepository>
<pluginRepository>
<id>rdc-snapshotsid>
<url>https://repo.rdc.aliyun.com/repository/你的私仓snapshots地址/url>
<releases>
<enabled>falseenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>rdcactiveProfile>
activeProfiles>
settings>