You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spotless Gradle插件:如何自定义Gherkin格式化器?

Spotless Gherkin Utils 自定义缩进及配置方案

默认调用gherkinUtils()时确实没有直接显示配置选项,但可以通过传入配置参数的方式自定义缩进大小等规则,具体是在gherkinUtils闭包中设置GherkinFormatterProperties的属性:

spotless {
  gherkin {
    target '**/*.feature'
    gherkinUtils {
      // 设置缩进为4个空格(默认是2)
      indentSize.set(4)
      // 可选:允许步骤之间保留空行(默认开启)
      allowBlankLinesBetweenSteps.set(true)
      // 可选:允许场景之间保留空行(默认开启)
      allowBlankLinesBetweenScenarios.set(true)
    }
  }
}

关键配置项说明

  • indentSize.set(n):控制.feature文件中步骤、场景描述等元素的缩进空格数,默认值为2。
  • allowBlankLinesBetweenSteps:决定步骤之间是否保留空行,默认值为true。
  • allowBlankLinesBetweenScenarios:控制场景之间是否保留空行,默认值为true。

如果需要更细致的格式控制,可以查看GherkinFormatterProperties类的其他可用方法,调整更多格式化规则。

内容的提问来源于stack exchange,提问作者pi lak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 08:27:01