当我只想使用 h2 内存数据库执行单元测试时,在 Maven 情况下使用这样的定义:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
当应用程序运行时我不需要 h2
为此目的,gradle 的类似物是什么?
最佳答案
H2 可能只在运行时被您的测试需要,即您的测试类不会针对任何 H2 类进行编译。在这种情况下,您应该使用 testRuntimeOnly
配置:
dependencies {
testRuntimeOnly 'com.h2database:h2'
}
对于您的测试类需要编译的依赖项,您应该使用 testImplementation
配置。
关于spring-boot - maven 的 <scope>test</scope> 的 gradle 模拟是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59239578/