http://www.open-open.com/lib/view/open1434522817864.html
如果你的公司有多个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文件中,加入以下配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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
//LibA
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中加入:
1
2
3
4
5
6
7
8
|
allprojects {
repositories {
mavenCentral()
//这里加入自己的maven地址
maven {
url
"http://127.0.0.1:8081/nexus/content/repositories/juude-id/"
}
}
|
然后在dependency里加入compile语句。
dependencies { ... compile 'net.juude.droidviews:droidViews:1.0' }
这样就可以正常使用了。