我想在我的测试中模仿依赖解析。我希望存储库将从sup项目的子项目继承。检查一下
Project sup = ProjectBuilder.builder().build()
sup.repositories {mavenCentral()}
Project sub = ProjectBuilder.builder().withParent(sup).build()
sup.repositories {mavenCentral()} //just to be sure
sub.apply plugin: 'java'
sub.dependencies {compile 'com.google.guava:guava:14.0'}
sub.configurations.findByName('compile').resolvedConfiguration.rethrowFailure()
但它失败了
org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':test:compile'.
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration.rethrowFailure(DefaultLenientConfiguration.java:52)
...
Caused by: org.gradle.api.internal.artifacts.ivyservice.ModuleVersionNotFoundException: Could not find group:com.google.guava, module:guava, version:14.0.
Required by:
test:test:unspecified
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LazyDependencyToModuleResolver$StaticVersionResolveResult.notFound(LazyDependencyToModuleResolver.java:159)
...
我可以通过添加sub.repositories {mavenCentral()}
来修复。但对我来说,它似乎应该没有它。
我仍然使用gradle 1.2
答案 0 :(得分:2)
Gradle使用配置注入而不是继承,这同样简洁但更清晰,更灵活。在您的情况下,您可以执行sup.allprojects { repositories { mavenCentral() } }
。
要详细了解配置注入,请参阅Injected configuration中的Gradle User Guide。