我在 AndroidStudio 上工作,我有一个结构如下的项目:
我的项目1
- |--- 模块通用
- |--- ModuleSocket(依赖ModuleCommon)
- |--- 模块演示
我想将 ModuleCommon 和 ModuleDemo 上传到我的本地 nexus 服务,我将在其他项目中使用 ModuleCommon 或(和)ModuleSocket,即我的 gradle 脚本(片段):
- ModuleCommon - build.gradle:
apply plugin: 'maven'
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
pom.groupId = GROUP
pom.artifactId = "ModuleCommon"
pom.version = "0.0.1"
repository(url: RELEASE_REPOSITORY_URL) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
}
}
}
task androidJavadocs(type: Javadoc) {
options.encoding = "UTF-8"
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
}
- ModuleSocket - build.gradle:此片段与 ModuleCommon - build.gradle 相同,但依赖项除外:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile ('xmrk:rkandroid:0.0.1')
}
- MyProject1 - build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
repositories {
maven {url "http://192.168.1.34:8081/nexus/content/repositories/releases"}
maven {url "http://192.168.1.34:8081/nexus/content/repositories/snapshots"}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
repositories {
maven {url "http://localhost:8081/nexus/content/repositories/releases"}
maven {url "http://localhost:8081/nexus/content/repositories/snapshots"}
}
}
}
- gradle.properties:
GROUP=xmrk
SNAPSHOT_REPOSITORY_URL=http://localhost:8081/nexus/content/repositories/snapshots/
RELEASE_REPOSITORY_URL=http://localhost:8081/nexus/content/repositories/releases/
NEXUS_USERNAME=myname
NEXUS_PASSWORD=mypassword
通过上面的脚本,我将我的库 ModuleCommon 和 ModuleSocket 上传到我的 nexus 服务器成功,但是当我使用 ModuleSocket 时,我得到一个错误:
错误:无法解决:xmrk:ModuleCommon:unspecified Open File
Show in Project Structure 对话框
有人救我吗?我觉得我的情况像Android Gradle 库依赖和使用 Nexus 的库依赖,但有一点差异,并且有差异错误。