【问题标题】:Android Gradle dependency local library using Nexus使用 Nexus 的 Android Gradle 依赖本地库
【发布时间】:2016-02-02 08:16:31
【问题描述】:

我在 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: 此 sn-p 与 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 打开文件
在项目结构对话框中显示


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

【问题讨论】:

  • 如果 xmrk:rkandroid 存在,你检查过 nexus repo 吗?
  • @GabrieleMariotti 存在,我可以使用它,我编辑依赖项来使用它,我成功了
  • 检查 pom 文件,特别是检查工件的版本,如果它是 0.0.1 或未指定。
  • maven.apache.org/POM/4.0.0" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache.org/POM/4.0.0 maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0xmrk ModuleSocket0.0.1aarxmrk ModuleCommon0.+compile 是我在 ModuleSocket 的关系中的 POM,似乎没问题
  • 检查 rkandroid 神器里面的 pom。检查依赖 vs ModuleSocket 是否正确。

标签: android gradle sonatype android-studio-2.0


【解决方案1】:

我通过删除 C:\Users[MyUsername].gradle\caches 中的缓存来解决这个问题。

认为@Gabriele

【讨论】:

    猜你喜欢
    • 2013-12-02
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    相关资源
    最近更新 更多