1

因此,我们目前正在努力将 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 和 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
4

3 回答 3

0

您已经仔细检查过“groupId:artifact2Id:artifact2Version”是否在您的工件存储库中?还是您不小心在这里依赖变量而不是字符串?

干杯,勒内

于 2013-06-07T23:46:25.757 回答
0

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

于 2013-06-18T09:23:17.830 回答
0

我发现默认情况下 gradle 会选择 androidsdk存储库:

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

代替:

C:\Users\YOUR_USER\.m2\repository

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

于 2013-07-06T02:54:29.170 回答