gradle 与 Maven 的 <scope>test</scope> 的类似物是什么?
What is the gradle's analogue for maven's <scope>test</scope>?
当我只想使用 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
配置。
当我只想使用 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
配置。