【问题标题】:What is the gradle's analogue for maven's <scope>test</scope>?maven 的 <scope>test</scope> 的 gradle 类比是什么?
【发布时间】:2020-04-02 00:10:56
【问题描述】:

当我只想使用 h2 memory db 执行单元测试并在 maven 案例中使用这样的定义时:

<dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
  </dependency>

应用程序运行时我不需要 h2

用于此目的的 gradle 类比是什么?

【问题讨论】:

    标签: spring-boot maven unit-testing gradle h2


    【解决方案1】:

    您的测试可能只在运行时需要 H2,即您的测试类不会针对任何 H2 类进行编译。在这种情况下,您应该使用testRuntimeOnly 配置:

    dependencies {
        testRuntimeOnly 'com.h2database:h2'
    }
    

    对于您的测试类需要编译的依赖项,您应该改用testImplementation 配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-19
      • 2011-06-19
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      相关资源
      最近更新 更多