spring-boot - maven 的 <scope>test</scope> 的 gradle 模拟是什么?

标签 spring-boot maven unit-testing gradle h2

当我只想使用 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/

相关文章:

spring-boot - 带有 Spring Boot 应用程序的 logack 中的 is_undefined 目录错误

java - 如何使用Spring Boot处理Rest API中的异常

java - 将jar库添加到Maven项目

unit-testing - 如何使用Supertest对文件上传进行单元测试-并发送 token ?

swift - 我如何在 XCODE 8 和 Swift 3 中使用 UIAutomation

javascript - 使用 javascript 动态生成 thymeleaf 输入并将其值发送到 Controller 不起作用

java - EclipseLink 从 Maven 项目中的数据库中选择实体

java - Maven编译错误: (use -source 7 or higher to enable diamond operator)

javascript - [ngModelOptions] ="{standalone: true}"的 Angular 单元测试失败

java - spring boot oauth ExceptionHandlerExceptionResolver : NestedServletException: nested exception is java. lang.StackOverflowError]