Android Gradle 使用 Nexus 的依赖本地库

Android Gradle dependency local library using Nexus

我在 AndroidStudio 上工作,我有一个结构如下的项目:

我的项目1

我想将 ModuleCommon 和 ModuleDemo 上传到我的本地 nexus 服务,我将在其他项目中使用 ModuleCommon 或(和)ModuleSocket,我的 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
    }
}
dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile ('xmrk:rkandroid:0.0.1')
}
// 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"}
        }
    }
}
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 时,我得到一个错误:

Error:Failed to resolve: xmrk:ModuleCommon:unspecified Open File
Show in Project Structure dialog


有人救救我吗?我觉得我的情况像 Android Gradle library dependency with library dependency using Nexus,但有一点差异,并且有差异错误。

我通过删除 C:\Users[MyUsername].gradle\caches.

中的缓存解决了这个问题

@Gabriele 认为