gradle spotless代码格式化

Last updated on November 22, 2024 pm

🧙 Questions

使用spotless格式化java代码

☄️ Ideas

添加依赖
plugins {
  id "com.diffplug.spotless" version "6.11.0"
} 

allprojects {
  apply plugin: "com.diffplug.spotless"
}
编辑配置
spotless {
    java {
        enforceCheck false
        importOrder()
        // 配置检测文件夹
        target '**/*.java'
        targetExclude 'spring-oxygen/*'
        // 使用google的规则
        googleJavaFormat('1.7')
        // 删除所有未用到import
        removeUnusedImports()
        // 结尾新起一行
        endWithNewline()
        // 起始4个空格
        indentWithTabs(2)
        indentWithSpaces(4)
        // 删除结尾空格
        trimTrailingWhitespace()
    }
}
执行格式化命令
# 代码检查
gradle spotlessJavaCheck

# 自动格式化
gradle spotlessJavaApply

20220930164611


gradle spotless代码格式化
https://ispong.isxcode.com/spring/gradle/gradle spotless代码格式化/
Author
ispong
Posted on
September 30, 2022
Licensed under