java-Gradle搜索常春藤服务,但未定义常春藤配置/回购
作者:互联网
我从Gradle中收到以下错误
Could not resolve all dependencies for configuration ':unitTestCompile'. > Could not find junit:junit:4.11.
这是我的build.gradle
apply plugin: 'android-library' buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.8.+' } } version = '0.6.2' configurations { unitTestCompile.extendsFrom runtime unitTestRuntime.extendsFrom unitTestCompile } dependencies { compile files('libs/android-support-v4.jar') unitTestCompile 'junit:junit:4.11' } android { buildToolsVersion "19.0.1" compileSdkVersion 17 sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src', 'bundled-src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } dependencies { compile fileTree(dir: './libs', include: 'Amplitude.jar') } } sourceSets { unitTest { java.srcDirs = ['tests/src'] res.srcDirs = ['tests/res'] assets.srcDirs = ['tests/assets'] resources.srcDirs = ['tests/res'] } } task doUnitTest(type:Test, dependsOn: assemble) { description = "run unit tests" testClassesDir = project.sourceSets.unitTest.output.classesDir classpath = 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
解决方法:
问题在于,您仅声明了构建脚本依赖项的存储库,而没有声明常规依赖项的存储库. (换句话说,您需要一个顶级存储库块.)此外,依赖项块应始终位于android块之外,因为它是Gradle的核心功能,与Android插件无关.
标签:android-gradle,maven,gradle,java,android 来源: https://codeday.me/bug/20191029/1962676.html