首页 > 解决方案 > gradle 中的自定义配置

问题描述

我在 gradle 中为 jupiter (Junit 5) 测试定义了单独的配置。我在 gradle 文件中有以下代码段:

我的理解是 jupiterCompile 将从 testCompile 扩展依赖项,包括为 self 定义的任何依赖项。在这种情况下,我的 testCompile 配置没有任何 jupiter 依赖项,但由于 jupiterCompile 具有这些依赖项集,我希望它们可用。但是,如果我写 testCompile.extendsFrom jupiterCompile 它确实有效,这让我感到困惑。

configurations {
jupiterTestCompile.extendsFrom testCompile
jupiterTestRuntime.extendsFrom testRuntime
jupiterTestCompileOnly.extendsFrom testCompileOnly
}
dependencies {
def jUnitVersion = "5.5.1"
jupiterTestCompile("org.junit.jupiter:junit-jupiter- 
api:${jUnitVersion}")
jupiterTestRuntime("org.junit.jupiter:junit-jupiter- 
engine:${jUnitVersion}")
jupiterTestCompileOnly("org.junit.jupiter:junit-jupiter- 
migrationsupport:${jUnitVersion}")
jupiterTestRuntime("org.junit.vintage:junit-vintage- 
engine:${jUnitVersion}")
}

如果我在 testCompile 下定义了公共依赖项并希望 jupiterCompile 配置继承它们,那么正确的配置应该是什么?

标签: gradleconfiguration

解决方案


推荐阅读