前言
最近學院搭服務器集群供大資料學習使用,平臺上的Hadoop全家桶使用CDH來搭建,由于國內沒有CDH版本的Maven依賴,負責搭集群的大佬在國外鏡像拉了依賴下來,但是整個倉庫打包又太麻煩,于是我來協助建一個私有倉庫,方便學院的同學們使用
本文主要記錄使用阿里云效來搭建Maven私有倉庫期間所踩的坑
選用阿里云效來搭Maven私倉的原因是
- 懶得自己搭Nexus服務了
- 免費
阿里云效的官方檔案(頁面截圖舊,不過勉強能搞懂怎么創建私倉),官方地址
導航
- 前言
- 搭建步驟
- 一、摸索
- 二、需要注意的坑
- 1. 本地倉庫到私倉的遷移
- 2. 本地Maven的配置
- profiles節點
- mirrors節點
- 3. 最終配置
搭建步驟
一、摸索
- 根據官方檔案,進入頁面,創建企業(其中會讓你進入新版云效,然后新版和舊版的企業是區別開的,在新版創建的企業不在舊版顯示,搞了我半天)
- 在舊版創建企業后,點擊如圖所示的地方進入私倉

- 進入后會提示你創建私倉,免費創建即可
- 出現如圖所示頁面,往下拉即是本地Maven的配置方法和本地倉庫遷移到私倉的方法

二、需要注意的坑
1. 本地倉庫到私倉的遷移
有了私倉,我們就直接把本地倉庫遷移到私倉了,按照如圖所示官方的方法進行遷移:

坑: 本地倉庫中,不能存在空目錄,否則遷移會報錯中止:

2. 本地Maven的配置
在按照官方的提示配置好Maven的配置(USER_HOME/.m2/settings.xml)后,可以正常deploy,但是還是無法下載私倉中的依賴,導致pom標紅,在翻看官方檔案和百度Maven私倉有關內容后仍然無果(上網查Maven私倉配置,跟官網的說明幾乎無二)
profiles節點
這是官網手動配置給出的說明

在添加profiles節點后,應在組態檔的后面追加:
<activeProfiles>
<!-- 你需要添加的profile節點的id,如上圖中的rdc-private-repo -->
<activeProfile>rdc-private-repo</activeProfile>
</activeProfiles>
如果activeProfiles節點中沒有你剛加入的profile節點的id,則該profile節點不會生效
mirrors節點
官方示例配置中并沒有提示用戶添加mirrors節點,這也是只能deploy而不能從私倉中下載依賴的原因
在mirrors節點中,應追加如下mirror節點:
<mirror>
<id>rdc-releases</id>
<mirrorOf>rdc-releases</mirrorOf>
<name>rdc-releases</name>
<url>https://repo.rdc.aliyun.com/repository/你的releases私倉地址/</url>
</mirror>
<mirror>
<id>rdc-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/你的snapshots私倉地址/</url>
<mirrorOf>rdc-snapshots</mirrorOf>
<name>rdc-snapshots</name>
</mirror>
注意: 此處mirror節點下的id,應與server節點下的id對應
在這個問題上搞了半天,只能感嘆自己的Maven基礎還不扎實,菜了

3. 最終配置
USER_HOME/.m2/settings.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<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>mirror</id>
<mirrorOf>central,jcenter</mirrorOf>
<name>mirror</name>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>rdc-releases</id>
<mirrorOf>rdc-releases</mirrorOf>
<name>rdc-releases</name>
<url>https://repo.rdc.aliyun.com/repository/你的私倉release地址/</url>
</mirror>
<mirror>
<id>rdc-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/你的私倉snapshots地址/</url>
<mirrorOf>rdc-snapshots</mirrorOf>
<name>rdc-snapshots</name>
</mirror>
</mirrors>
<servers>
<server>
<id>rdc-releases</id>
<username>你的用戶名</username>
<password>你的密碼</password>
</server>
<server>
<id>rdc-snapshots</id>
<username>你的用戶名</username>
<password>你的密碼</password>
</server>
</servers>
<profiles>
<profile>
<id>rdc</id>
<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>central</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>rdc-releases</id>
<url>https://repo.rdc.aliyun.com/repository/你的私倉release地址</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>rdc-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/你的私倉snapshots地址/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>https://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>rdc-releases</id>
<url>https://repo.rdc.aliyun.com/repository/你的私倉release地址</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>rdc-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/你的私倉snapshots地址/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>rdc</activeProfile>
</activeProfiles>
</settings>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/248072.html
標籤:其他
下一篇:我為何推薦你學習C語言
