使用Gradle

时间:2015-05-20 21:37:32

标签: android maven gradle artifactory

我有一个已发布到我当地Artifactory存储库的工件,现在我正试图将该工件拖入带有gradle的项目中。

但是,我一直收到以下错误:

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.company.app:myapplication:1.0.0.
     Searched in the following locations:
     https://jcenter.bintray.com/com/company/app/...pom
     https://jcenter.bintray.com/com/company/app/...jar

     file:/Users/user/Library/Android/sdk/extras/android/m2repository/com/company/app...pom
     file:/Users/user/Library/Android/sdk/extras/android/m2repository/com/company/app...jar
     file:/Users/user/Library/Android/sdk/extras/google/m2repository/com/company/app...pom
     file:/Users/user/Library/Android/sdk/extras/google/m2repository/com/company/app....jar

此错误表明它甚至没有查看本地神器存储库。以下是我的build.gradle文件

项目级别build.gradle

buildscript {
    repositories {
        jcenter()
        maven {
            url '${artifactory_contextUrl}/libs-release-local'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.0"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

应用级build.gradle

allprojects{
    apply plugin: "com.jfrog.artifactory"
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.company.app:myapplication:1.0.0'
}

1 个答案:

答案 0 :(得分:7)

问题是

  1. maven url需要在buildscript之外
  2. maven网址需要处于应用级别,而不是项目级别build.gradle
  3. 以下是我当前使用的build.gradle个文件:

    项目级别build.gradle

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.1.0'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    应用级build.gradle

    repositories {
        maven {
            url '${artifactory_contextUrl}/libs-release-local'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
    }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.company.app:myapplication:1.0.0'
    }
    

    注意:我删除了jfrog插件,因为只有在您发布到Artifactory时才需要它。