Gradle 搜索 Ivy 服务但未定义 Ivy 配置/存储库
Posted
技术标签:
【中文标题】Gradle 搜索 Ivy 服务但未定义 Ivy 配置/存储库【英文标题】:Gradle searching Ivy service but no Ivy config / repo defined 【发布时间】:2014-04-14 04:10:57 【问题描述】:我从 Gradle 收到以下错误
无法解析配置“:unitTestCompile”的所有依赖项。 > 找不到 junit:junit:4.11。这是我的 build.gradle
应用插件:'android-library' 构建脚本 存储库 mavenCentral() 依赖 类路径'com.android.tools.build:gradle:0.8.+' 版本 = '0.6.2' 配置 unitTestCompile.extendsFrom 运行时 unitTestRuntime.extendsFrom unitTestCompile 依赖 编译文件('libs/android-support-v4.jar') unitTestCompile 'junit:junit:4.11' 安卓 构建工具版本“19.0.1” compileSdkVersion 17 源集 主要的 manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src', 'bundled-src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] 依赖 编译文件树(目录:'./libs',包括:'Amplitude.jar') 源集 单元测试 java.srcDirs = ['测试/src'] res.srcDirs = ['测试/资源'] assets.srcDirs = ['测试/资产'] resources.srcDirs = ['tests/res'] 任务doUnitTest(类型:测试,依赖:组装) 描述 =“运行单元测试” testClassesDir = project.sourceSets.unitTest.output.classesDir 类路径 = project.sourceSets.unitTest.runtimeClasspath check.dependsOn doUnitTest调试运行表明它正在尝试使用 Ivy 而不是使用 Maven 来解决依赖关系?
16:21:58.633 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration :analytics-android:0.6.2(unitTestCompile).
16:21:58.633 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting dependency :analytics-android:0.6.2(unitTestCompile) -> junit:junit:4.11(dependency: junit#junit;4.11 unitTestCompile=[default])
16:21:58.634 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Selecting new module version junit:junit:4.11
16:21:58.634 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain] Attempting to resolve module 'junit:junit:4.11' using repositories []
16:21:58.636 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Attaching :analytics-android:0.6.2(unitTestCompile) to its parents.
16:21:58.637 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResultsBuilder] Flushing resolved configuration data in Binary store in /private/var/folders/7y/yrtq1vcx3xb901v_xd5v5_100000gn/T/gradle1413382664789288993.bin. Wrote root :analytics-android:0.6.2:unitTestCompile.
16:21:58.638 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':compileUnitTestJava'
16:21:58.638 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :compileUnitTestJava (Thread[main,5,main]) completed. Took 0.017 secs.
16:21:58.639 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 4.035 secs, idle: 0.047 secs
16:21:58.644 [ERROR] [org.gradle.BuildExceptionReporter]
16:21:58.645 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
16:21:58.645 [ERROR] [org.gradle.BuildExceptionReporter]
16:21:58.646 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:21:58.646 [ERROR] [org.gradle.BuildExceptionReporter] Could not resolve all dependencies for configuration ':unitTestCompile'.
16:21:58.646 [ERROR] [org.gradle.BuildExceptionReporter] > Could not find junit:junit:4.11.
16:21:58.646 [ERROR] [org.gradle.BuildExceptionReporter] Required by:
16:21:58.647 [ERROR] [org.gradle.BuildExceptionReporter] :analytics-android:0.6.2
【问题讨论】:
【参考方案1】:问题是您只为构建脚本依赖项声明了一个存储库,而没有为常规依赖项声明一个存储库。 (换句话说,您需要一个***的 repositories
块。)此外,dependencies
块应该始终位于 android
块之外,因为它是与 Android 插件无关的核心 Gradle 功能。
【讨论】:
以上是关于Gradle 搜索 Ivy 服务但未定义 Ivy 配置/存储库的主要内容,如果未能解决你的问题,请参考以下文章
如何使用自定义 gradle 插件而不将其发布到 maven/ivy 存储库?
使用 Gradle ivy-publish 插件生成 ivy.xml