Gradle构建无法从自定义maven存储库获取依赖关系

时间:2014-08-23 21:08:12

标签: android maven gradle android-studio build.gradle

我在link之后在BitBucket上创建了一个自定义maven仓库。当我尝试使用Gradle在我的android项目中使用依赖项时,我收到以下错误

Executing tasks: [:app:compileDebugJava]

Configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
Checksum missing at https://bitbucket.org/test/maven-repo/raw/master/repository/com/test/com/testCommon/1.0/testCommon-1.0.pom.sha1 due to: For input string: "<!"
Download https://bitbucket.org/test/maven-repo/raw/master/repository/com/test/com/testCommon/1.0/testCommon-1.0.pom

[Fatal Error] testCommon-1.0.pom:2:10: Already seen doctype.

Checksum missing at https://bitbucket.org/test/maven-repo/raw/master/repository/com/android/support/support-v4/20.0.0/support-v4-20.0.0.pom.sha1 due to: For input string: "<!"
Download https://bitbucket.org/test/maven-repo/raw/master/repository/com/android/support/support-v4/20.0.0/support-v4-20.0.0.pom

[Fatal Error] support-v4-20.0.0.pom:2:10: Already seen doctype.

Checksum missing at https://bitbucket.org/test/maven-repo/raw/master/repository/com/android/support/support-annotations/20.0.0/support-annotations-20.0.0.pom.sha1 due to: For input string: "<!"
Download https://bitbucket.org/test/maven-repo/raw/master/repository/com/android/support/support-annotations/20.0.0/support-annotations-20.0.0.pom

[Fatal Error] support-annotations-20.0.0.pom:2:10: Already seen doctype.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not resolve com.test.com:testCommon:1.0.
     Required by:
         SettingsAid:app:unspecified
      > Could not parse POM https://bitbucket.org/test/maven-repo/raw/master/repository/com/test/com/testCommon/1.0/testCommon-1.0.pom
         > Already seen doctype.

我更改了链接。但是直接打开链接会返回校验和。

以下是我的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'maven'
android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.test.sampleapp"
        minSdkVersion 11
        targetSdkVersion 19
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
repositories {
    mavenCentral()
    maven {
        credentials {
            username "test@gmail.com"
            password "test"
        }
        url "https://bitbucket.org/test/maven-repo/raw/master/repository/"
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.test.com:testCommon:1.0'
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

我不确定我在这里做错了什么。我也遵循了link。任何人都可以帮我解决这个问题。

更新1:

当我检查〜.gradle文件夹时,即使在提供凭据后,它也没有登录并保存整页。当我将我的回购从私有更改为公开时,代码就开始工作了。但我不想让我的回购公开。如何让gradle使用传递的登录凭据?

感谢。

4 个答案:

答案 0 :(得分:3)

我通过将repo路径更改为:

来修复此问题
"https://"+username+":"+password+"@bitbucket.org/test/maven-repo/raw/master/repository/"

用户名和密码在gradle.properties中设置。

答案 1 :(得分:2)

我的团队和我使用Bitbucket REST API解决了它,您可以在此答案中找到更多详细信息:https://stackoverflow.com/a/30117276/4877779

答案 2 :(得分:1)

我过去常常和这个问题斗争三天。根据你的代码,这是我的解决方案。希望能拯救你的生命。

  1. 你的maven网址错了。请使用bitbuckest.org的正确api。并且网址格式应为https://api.bitbucket.org/1.0/repositories/team-or-user-name/prject-name/raw/branch-name。例如:https://api.bitbucket.org/1.0/repositories/yolonetltd/yolonet-mvn-repo/raw/releases/请注意,请勿使用api.bitbucket.org/2.0,请使用api.bitbucket.org/1.0!

    repositories {
        mavenCentral()
            maven {
                credentials {
                    username "xxxxx" // note, not email, use login user name please!
                    password "xxxxx"
                }
                url "https://api.bitbucket.org/1.0/repositories/test/maven-repo/raw/master" // note, use api 1.0, do not use api 2.0!
            }
        }
    
  2. 如果您的依赖项是 aar 格式,则应在依赖项描述之后添加@aar。依赖关闭应该如下所示。否则gradle将抛出依赖性未找到错误。

    dependencies {
        ...
        compile 'com.test.com:testCommon:1.0@aar'
        ...
    }
    
  3. 确保您的远程bitbucket maven存储库保存完整的文件目录,如下所示。否则gradle也会抛出依赖未找到的错误。

    |   ├── com
    │   ├── as-gradle
    │   │   └── demo
    │   │       └── localrepo
    │   │           ├── 1.0.0
    │   │           │   ├── localrepo-1.0.0.aar
    │   │           │   ├── localrepo-1.0.0.aar.md5
    │   │           │   ├── localrepo-1.0.0.aar.sha1
    │   │           │   ├── localrepo-1.0.0.pom
    │   │           │   ├── localrepo-1.0.0.pom.md5
    │   │           │   └── localrepo-1.0.0.pom.sha1
    │   │           ├── maven-metadata.xml
    │   │           ├── maven-metadata.xml.md5
    │   │           └── maven-metadata.xml.sha1
    

答案 3 :(得分:0)

add   authentication {

            basic(BasicAuthentication)
        }

        maven {
            credentials {
                username ''
                password ''
            }
            authentication {
                basic(BasicAuthentication)
            }
            url "https://bitbucket.org/USER/REPO/raw/BRANCH/"
        }
    }