1

我想在我的测试中模仿依赖解决。我希望存储库将由 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

4

1 回答 1

2

Gradle 使用配置注入代替继承,同样简洁但更干净、更灵活。在您的情况下,您可以执行类似sup.allprojects { repositories { mavenCentral() } }.

要了解有关配置注入的更多信息,请参阅Gradle 用户指南中的注入配置

于 2013-06-05T12:42:52.463 回答