Spring 引导,从 Gradle 5 中的测试中排除依赖项

Spring boot, exclude dependencies from test in Gradle 5

我想从测试中排除两个 jar,并且只在应用程序实际 运行 时才使用它们。

dependencies {
    runtimeOnly('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
    runtimeOnly('org.springframework.cloud:spring-cloud-starter-config')
}

如何明确告诉 Gradle 5 在 运行 测试期间不要加载这些 jar?我已经禁用了它们的使用,但它们仍然会继续加载。我希望得到像下面这样简单的东西,但我一直无法找到决定性的答案。

test.exclude {
    group 'org.springframework.cloud'
}

编辑

复制粘贴解决方案

configurations.testCompile.exclude(group: 'org.springframework.cloud', module: 'spring-cloud-starter-netflix-eureka-client')
configurations.testCompile.exclude(group: 'org.springframework.cloud', module: 'spring-cloud-starter-config')

在您的 dependencies 块中,您可以执行以下操作:

configurations.testCompile.exclude(group: 'the-group', module: 'the-module')

希望对您有所帮助!