Android:使用Gradle解决与Artifactory的外部依赖关系 [英] Android : resolve external dependencies over Artifactory with Gradle

查看:679
本文介绍了Android:使用Gradle解决与Artifactory的外部依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们目前正在将Android项目的ant构建/发布脚本迁移到新的Android Gradle构建系统。

So we are currently working on the migration of ant building/publishing scripts for Android projects to the new Android Gradle build system.

我们的项目通常依赖于内部和第三方图书馆。内部图书馆已经发布在Artifactory存储库上,现在我正在努力解决它们的依赖。

Our projects generally relies on both internal and third-party libraries. The internal libraries have been published on Artifactory repositories and now I'm struggling to resolve the dependencies over them.

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()行。但是,当我尝试建立这个错误时,我发现了这个错误(而且我一直在尝试这个小小的变化):

I basically used built-in options in Artifactory to generate the artifactory{} section and the two compile() lines. But I'm having this error when trying to build (and I keep having it whatever minor changes I tried) :

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&人工制品,我觉得有点迷失了。有人可以启发我,或者告诉我如何获得更准确的问题信息(我尝试过--debug和--info,-s和--S选项,这不是很有帮助)。初始异常总是:

I'm probably missing something big, but as a newcomer to Gradle, Maven & Artifactory, I feel kinda lost for the moment. Can someone enlighten me or perhaps tell me how can I get more precise informations on the problem (I tried the --debug and --info, --s and --S options and it was not very helpful). The initial exception is always :

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。相反,我得到以下(我想,不是我应该拥有的):

The 'gradle refresh-dependencies --info' command didn't give more useful information. What is very troubling though is that the debug traces never mentionned the contextUrl I provided. Instead I got the following (which, I suppose, is not what I should have) :

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


推荐答案

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

As @noamt said the only thing wrong was the fact I was not declaring a repositories {} section that actually allows the connection with Artifactory. I am still a bit confused why this is not directly handled by the artifactory {} section but at least it is working now.

这篇关于Android:使用Gradle解决与Artifactory的外部依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆