Android私有Maven倉(cāng)庫(kù)搭建及arr打包上傳

環(huán)境

系統(tǒng):windows10
JDK:Oracle JDK 1.8
倉(cāng)庫(kù)軟件:Nexus Repository Manager OSS 3.x

一、Nexus Repository Manager OSS 3.x 安裝及配置

1.下載

官網(wǎng): https://www.sonatype.com/
下載地址: https://www.sonatype.com/nexus-repository-oss
官方文檔: https://help.sonatype.com/repomanager3
下載的時(shí)候選擇Nexus Repository OSS,帶Pro的是收費(fèi)版。不需要登錄,輸入任意郵箱就可以下載了。

2.安裝

下載后是個(gè)壓縮包,軟件是綠色版,不用安裝,直接解壓到指定目錄就可以了。但是Windows用戶需注意目錄路徑不能含有中文,空格等字符。官方文檔還說不要放到Program Files,因?yàn)闀?huì)有注冊(cè)問題,另外注意文件夾權(quán)限等,總之,怕麻煩別放C盤吧。
我下載的壓縮包有兩個(gè)文件夾,一個(gè)是nexus-3.28.0-01,另外一個(gè)是sonatype-work。不同版本可能不一樣。

Nexus Repository Manager should not be installed in the Program Files directory to avoid problems with Windows file registry virtualization. If you plan to run the repository manager as a specific user you can install it into the AppData\Local directory of that users home directory. Otherwise simply use e.g., C:\nexus or something similar, ensuring that the user running the application has full access.

3.配置

打開D:\SonatypeNexus\nexus-3.28.0-01\etc\nexus-default.properties。注意不是sonatype-work下的etc。

# Jetty 訪問端口,默認(rèn)是8081
application-port=8081
# 本機(jī)地址
application-host=0.0.0.0

4.啟動(dòng)服務(wù)

4.1直接啟動(dòng)

使用管理員權(quán)限運(yùn)行cmd,進(jìn)入Nexusbin目錄下執(zhí)行nexus.exe /run

C:\Windows\system32>D:
D:\>cd D:\SonatypeNexus\nexus-3.28.0-01\bin
D:\SonatypeNexus\nexus-3.28.0-01\bin>nexus.exe /run

第一次啟動(dòng)比較慢,等到打印出來下面的內(nèi)容就啟動(dòng)成功了。

-------------------------------------------------

Started Sonatype Nexus OSS 3.12.0-01

-------------------------------------------------

這個(gè)啟動(dòng)成功之后,服務(wù)就啟動(dòng)了,這個(gè)時(shí)候就可以訪問控制臺(tái)了 http://localhost:8081/
關(guān)閉cmd窗口可以停止服務(wù)。

4.2安裝成windows服務(wù)

進(jìn)入nexusbin目錄,執(zhí)行nexus.exe /install <optional-service-name>

D:\SonatypeNexus\nexus-3.28.0-01\bin>nexus.exe /install nexus
Installed service 'nexus'.

其他服務(wù)操作指令

#啟動(dòng)
nexus.exe /start <optional-service-name>
#停止
nexus.exe /stop <optional-service-name>
#卸載
nexus.exe /uninstall <optional-service-name>

5.使用

打開http://localhost:8081/
點(diǎn)擊右上角Sign in,輸入賬號(hào)密碼,管理員賬號(hào)是admin,密碼是存儲(chǔ)在本地一個(gè)文件中,首次登錄,在登錄窗口有提示密碼文件位置,用文本查看工具打開就可以看到密碼,修改了管理員密碼后,該文件就會(huì)消失。

登錄

點(diǎn)擊齒輪狀按鈕,可進(jìn)入配置頁面,進(jìn)入Repository-Repositories:


image.png

Repository的type屬性有:proxy,hosted,group三種。

proxy:即你可以設(shè)置代理,設(shè)置了代理之后,在你的nexus中找不到的依賴就會(huì)去配置的代理的地址中找;
hosted:你可以上傳你自己的項(xiàng)目到這里面;
group:它可以包含前面兩個(gè),是一個(gè)聚合體。一般用來給客戶一個(gè)訪問nexus的統(tǒng)一地址。

簡(jiǎn)單的說,就是你可以上傳私有的項(xiàng)目到hosted,以及配置proxy以獲取第三方的依賴(比如可以配置中央倉(cāng)庫(kù)的地址)。前面兩個(gè)都弄好了之后,在通過group聚合給客戶提供統(tǒng)一的訪問地址。

至于format,因?yàn)楸疚闹v的的 Maven Repository ,所以請(qǐng)選擇maven2;

你還可以添加一個(gè)國(guó)內(nèi)的私有maven庫(kù)作為代理,避免中央庫(kù)無法連接,譬如阿里云:
http://maven.aliyun.com/nexus/content/groups/public/

系統(tǒng)默認(rèn)就有以上幾個(gè)Repository。點(diǎn)擊maven-public 確保已經(jīng)將 maven-central,maven-releases以及maven-snapshots都包含在里面,如果你自己有自定義庫(kù),請(qǐng)確保也在里面。

image.png

maven-releases : 默認(rèn)配置只能上傳 release版本的項(xiàng)目
maven-snapshots: 默認(rèn)配置只能上傳 snapshots版本的項(xiàng)目
nuget開頭的庫(kù): .net使用的庫(kù),java不用管

如有特殊要求,可以自己創(chuàng)建一個(gè)Version policy 為Mixed的Repository。

以上配置就能滿足一般需求了。

  • 添加用戶
    找到 Security > Users , 點(diǎn)擊 Create local user 添加新用戶.
    image.png

二、AndroidStudio上傳arr

1. 打包上傳

修改需要打包的module下的的build.gradle

//引入maven插件
apply plugin: 'maven'

def RELEASE_REPOSITORY_URL = "http://localhost:8081/repository/zii-host/"
def SNAPSHOT_REPOSITORY_URL = "http://localhost:8081/repository/zii-host/"
def REPOSITORY_RUL = RELEASE_REPOSITORY_URL;
def NEXUS_USERNAME = "zii4914"
def NEXUS_PASSWORD = "----"

def GROUP_ID="com.github.zii4914"
def VERSION_NAME="v1.1.0"
def ARTIFACT_ID="mylib"

uploadArchives {
    repositories.mavenDeployer {

        repository(url: REPOSITORY_RUL) {
            authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
        }
        // 快照倉(cāng)庫(kù)地址(可選)
        snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
            authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
        }

        pom.project {
            name  ARTIFACT_ID// artifact名稱
            version VERSION_NAME // artifact版本
            artifactId ARTIFACT_ID // artifact id
            groupId GROUP_ID // artifact所屬Group Id
            packaging 'aar' // 文件格式
            description 'mylib package v' + VERSION_NAME // 描述
        }
    }
}

代碼編譯之后,在側(cè)邊Gradle窗口找到該模塊下的upload任務(wù),執(zhí)行uploadArchives任務(wù),會(huì)把module打包成arr,并且上傳到倉(cāng)庫(kù)中。
上傳成功后可以在倉(cāng)庫(kù)中看到相關(guān)信息

image.png

2. 引用依賴

//項(xiàng)目根目錄下`build.gradle`
allprojects {
    repositories {
        google()
        jcenter()
        maven {
            //我在maven-public里面加入了自己新建的zii-host,所以可以從這里找到我的包
            url "http://localhost:8081/repository/maven-public/"
        }
    }
}

//在需要的模塊中,添加依賴
 implementation 'com.github.zii4914:mylib:v1.1.0'

參考

CSDN > Nexus Repository Manager OSS 3.x 安裝配置
簡(jiǎn)書 > Maven私服Nexus 3.x搭建

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容