其他分享
首页 > 其他分享> > android – 使用Gradle从Artifactory访问依赖项

android – 使用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()
    }
}

App Level build.gradle

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

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

解决方法:

问题是

> maven url需要在buildscript之外
> maven url需要处于App级别,而不是Project级别build.gradle

以下是我当前的build.gradle文件:

项目级build.gradle

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

allprojects {
    repositories {
        jcenter()
    }
}

App Level 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时才需要它.

标签:android,maven,gradle,artifactory
来源: https://codeday.me/bug/20190727/1558625.html