首页 > 解决方案 > Spring boot,从 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')

标签: spring-bootgradlebuild.gradle

解决方案


在您的依赖项块中,您可以执行以下操作:

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

希望这可以帮助!


推荐阅读