gpt4 book ai didi

testing - 在多模块项目中继承存储库

转载 作者:行者123 更新时间:2023-11-28 20:32:05 24 4
gpt4 key购买 nike

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

最佳答案

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

要了解有关配置注入(inject)的更多信息,请参阅 Injected configurationGradle User Guide .

关于testing - 在多模块项目中继承存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16938539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com