Android Gradle库依赖与库依赖使用Nexus

我把我的项目切换到使用Gradle和内部SonaType Nexus托管我的依赖。我的核心项目依赖于库项目A和库项目A对库项目B有依赖。

我的问题是,一旦我添加LibA到我的主要项目,我得到这个错误:
“模块版本com.example:LibA:1.1依赖于库,但不是一个库本身”

我没有问题添加库项目与jar依赖与相同的构建脚本。我已经看到人们这样做成功与LOCAL(在项目中)android库,但没有人做它与maven repos。

这是gradle中的错误还是我错误配置库构建?

核心项目构建

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    maven {
        url "http://localhost:8081/nexus/content/repositories/releases/"
    }

    maven {
        url "http://localhost:8081/nexus/content/repositories/central/"
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile('com.example:LibA:1.+')
}

LibA构建

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17

        versionCode = "3"
        versionName = "1.2"
    }

    android {
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aild.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        compile ('com.example:LibB:1.+')
    } ...

LibB构建

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17

        versionCode = "1"
        versionName = "1.0"
    }

    android {
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aild.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
    } ...

编辑:为错误添加-info输出。

* What went wrong:
A problem occurred configuring project ':GradleTest'.
> Failed to notify project evaluation listener.
   > Module version com.example:LibA:1.+ depends on libraries but is not a library itself

编辑2:为LibA添加我的本地maven上传脚本

apply plugin: 'maven'
apply plugin: 'signing'

group = "com.example"
version = defaultConfig.versionName

configurations {
    archives {
        extendsFrom configurations.default
    }
}

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: sonatypeRepo) {
            authentication(userName: sonatypeUsername,
                    password: sonatypePassword)
        }

        pom.project {
            name 'com-example'
            packaging 'aar'
            description 'none'
            url 'https://internal github link'

            scm {
                url 'scm:git@https://internal github link'
                connection 'git@https://internal github link'
                developerConnection 'git@https://internal github link'
            }

            licenses {
                license {
                    name 'example'
                    url 'example'
                    distribution 'example'
                }
            }

            developers {
                developer {
                    id 'example'
                    name 'example'
                    email 'example'
                }
            }

            groupId "com.example"
            artifactId rootProject.name //LibA
            version defaultConfig.versionName
        }
    }
}
你的在依赖包中包含LibA的行是错误的。要包括库项目,请使用:

compile project(':LibA')

如果库的目录不在项目目录的根目录,您需要指定冒号分隔的路径。例如,如果您的目录结构是:

projectFolder
  |
  +--coreProject
  |
  +--libraries
      |
      +--LibA
      |
      +--LibB

你的依赖将是:

compile project(':libraries:LibA')

这与您在settings.gradle文件中使用的符号相同。

http://stackoverflow.com/questions/20061652/android-gradle-library-dependency-with-library-dependency-using-nexus

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:Android Gradle库依赖与库依赖使用Nexus