-
公開課1108:域名與DNS系統
如果你的公司有多個Android app應用需要開發,那麼很有可能你需要私有的公共庫。本文介紹如何使用sonar nexus搭建maven倉庫。
1. 安裝Nexus
從 http://www.sonatype.org/nexus/go/上下載tar.gz或者zip格式壓縮包。並且解壓到本地,然後進入bin目錄,執行nexus
cd nexus-2.11.1-01/bin
./nexus start
在瀏覽器中輸入: 127.0.0.1:8081/nexus 可以看到這樣的頁面
,表示已經安裝成功了。
2. 建立倉庫
使用nexus默認賬戶名admin,密碼admin123。登錄進去看到已經建立了十幾個倉庫。
點擊工具欄add -> 選擇hosted repository,然後填入repository id,和repository name-> 保存,這樣就可以建立新的倉庫了。
如圖,建立了一個名爲juude的倉庫。
3. 上傳library
在已經建好的android library項目的build.gradle文件中,加入以下配置:
apply plugin: 'maven'
apply plugin: 'signing'
....
signing {
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: 'http://127.0.0.1:8081/nexus/content/repositories/juude-id/') {
authentication(userName: "admin",
password: "admin123")
}
pom.project {
name 'juude-library'
packaging 'aar'
description 'none'
url 'http://127.0.0.1:8081/nexus/content/repositories/juude-id/'
groupId "net.juude.droidviews"
artifactId rootProject.name
version android.defaultConfig.versionName
}
}
}
現在在項目根目錄執行 ./gradlew
tasks ,就可以看到多了一個選項:
Upload tasks
------------
uploadArchives - Uploads all artifacts belonging to configuration ':library:archives'
然後執行
./gradlew uploadArchives
如果沒有報錯,就成功上傳自己的library了。
4. 使用library
由於沒有使用maven center,使用的時候需要提供自己的url地址,在build.gradle中加入:
allprojects {
repositories {
mavenCentral()
maven {
url "http://127.0.0.1:8081/nexus/content/repositories/juude-id/"
}
}
然後在dependency里加入compile語句。
dependencies {
...
compile 'net.juude.droidviews:droidViews:1.0'
}
這樣就可以正常使用了。
|