Android:使用Gradle解决Artifactory上的外部依赖关系

时间:2013-06-07 13:59:12

标签: android dependencies gradle libraries artifactory

因此,我们目前正致力于将Android项目的ant构建/发布脚本迁移到新的Android Gradle构建系统。

我们的项目通常依赖于内部和第三方库。内部库已经发布在Artifactory存储库中,现在我正在努力解决它们之间的依赖关系。

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }

        maven{
            url 'http://dl.bintray.com/jfrog/jfrog-jars'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.1.0')
    }
}
apply plugin: 'android'
apply plugin: 'artifactory'

artifactory {
    contextUrl = 'my_artifactory_url'

    resolve {
        repository {
            repoKey = 'libs-snapshot'
            maven = true
        }
    }
}

dependencies {
    compile files('libs/android-support-v4.jar')
    compile(group: 'groupId', name: 'artifact1Id', version: 'artifact1Version')
    compile(group: 'groupId', name: 'artifact2Id', version: 'artifact2Version')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

我基本上使用了Artifactory中的内置选项来生成artifactory {}部分和两个compile()行。但是我在尝试构建时遇到了这个错误(并且我继续使用它,无论我尝试了什么小的改动):

15:34:23.208 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
15:34:23.209 [ERROR] [org.gradle.BuildExceptionReporter] 
15:34:23.210 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
15:34:23.210 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred configuring project ':GradleArtifactoryTest'.
15:34:23.210 [ERROR] [org.gradle.BuildExceptionReporter] > Failed to notify project evaluation listener.
15:34:23.211 [ERROR] [org.gradle.BuildExceptionReporter]    > Could not resolve all dependencies for configuration ':GradleArtifactoryTest:compile'.
15:34:23.211 [ERROR] [org.gradle.BuildExceptionReporter]       > Could not find groupId:artifact1Id:artifact1Version.
15:34:23.212 [ERROR] [org.gradle.BuildExceptionReporter]         Required by:
15:34:23.212 [ERROR] [org.gradle.BuildExceptionReporter]             workspace_gradle-artifactory-test:GradleArtifactoryTest:unspecified
15:34:23.213 [ERROR] [org.gradle.BuildExceptionReporter]       > Could not find groupId:artifact2Id:artifact2Version.
15:34:23.213 [ERROR] [org.gradle.BuildExceptionReporter]         Required by:
15:34:23.214 [ERROR] [org.gradle.BuildExceptionReporter]             workspace_gradle-artifactory-test:GradleArtifactoryTest:unspecified

我可能错过了一些重要的东西,但作为Gradle,Maven和amp;的新手。 Artifactory,我觉得有点失落。有人可以启发我或者告诉我如何才能获得有关问题的更准确信息(我尝试了--debug和--info, - s和--S选项,但这并不是很有帮助)。最初的例外总是:

Caused by: org.gradle.api.internal.artifacts.ivyservice.ModuleVersionNotFoundException: Could not find groupId:artifact1Id:artifact1Version.
Required by:
14:20:51.833 [ERROR] [org.gradle.BuildExceptionReporter]     workspace_gradle-artifactory-test:GradleArtifactoryTest:unspecified
14:20:51.833 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LazyDependencyToModuleResolver$StaticVersionResolveResult.notFound(LazyDependencyToModuleResolver.java:148)
14:20:51.834 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LazyDependencyToModuleResolver$AbstractVersionResolveResult.resolve(LazyDependencyToModuleResolver.java:89)
14:20:51.834 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ModuleVersionSelectorResolveState.resolve(DependencyGraphBuilder.java:943)
14:20:51.835 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DefaultModuleRevisionResolveState.getMetaData(DependencyGraphBuilder.java:648)
14:20:51.835 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.calculateTargetConfigurations(DependencyGraphBuilder.java:333)
14:20:51.836 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.attachToTargetConfigurations(DependencyGraphBuilder.java:309)
14:20:51.836 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:130)
14:20:51.836 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:66)
14:20:51.837 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:7

'gradle refresh-dependencies --info'命令没有提供更多有用的信息。但令人不安的是调试跟踪从未提及我提供的contextUrl。相反,我得到了以下(我想,这不是我应该拥有的):

selecting new module version groupId#artifact1Id;artifact1Version
16:58:08.827 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain] Attempting to resolve module 'groupId:artifact1Id:artifact1Version' using repositories [maven, maven2]
16:58:08.829 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] Loading /Applications/Android Studio.app/sdk/extras/android/m2repository/groupId/artifact1Id/artifact1version/artifact1Id-artifact1Version.pom
16:58:08.832 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] Resource not reachable for groupId#artifact1Id;artifact1Version: res=MissingResource: /Applications/Android Studio.app/sdk/extras/android/m2repository/groupId/artifact1Id/artifact1version/artifact1Id-artifact1Version.pom
16:58:08.833 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] Loading /Applications/Android Studio.app/sdk/extras/android/m2repository/groupId/artifact1Id/artifact1version/artifact1Id-artifact1Version.apklib
16:58:08.840 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] Resource not reachable for groupId#artifact1Id;artifact1Version: res=MissingResource: /Applications/Android Studio.app/sdk/extras/android/m2repository/groupId/artifact1Id/artifact1version/artifact1Id-artifact1Version.apklib

3 个答案:

答案 0 :(得分:0)

你仔细检查了“groupId:artifact2Id:artifact2Version”是否在你的神器库中?或者你是否意外地依赖于变量而不是字符串?

欢呼声, 勒

答案 1 :(得分:0)

正如@noamt所说,唯一不对的是我没有声明一个实际允许与Artifactory连接的存储库{}部分。我仍然有点困惑为什么这不是由artifactory {}部分直接处理,但至少它现在正在工作。

答案 2 :(得分:0)

我发现gradle默认选择了android sdk存储库:

C:\Users\YOUR_USER\android-sdks\extras\android\m2repository

而不是:

C:\Users\YOUR_USER\.m2\repository

在寻找工件时,但下载它们的时候。进行比较并检查它们是否在第二个中下载。