Spring Java Format
- https://github.com/spring-io/spring-javaformat
- https://github.com/spring-io/spring-javaformat/blob/main/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
Gradle 项目中使用
build.gradle 配置
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.41"
}
}
plugins {
id "checkstyle"
}
checkstyle {
toolVersion = "9.3"
}
allprojects {
repositories {
mavenCentral()
}
apply plugin: 'checkstyle'
apply plugin: 'io.spring.javaformat'
dependencies {
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.41")
}
}
Spring Java Format 配置文件
.springjavaformatconfig
indentation-style=spaces
checkstyle 配置文件
config/checkstyle/checkstyle.xm
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="com.puppycrawl.tools.checkstyle.Checker">
<module name="io.spring.javaformat.checkstyle.SpringChecks" >
<property name="tabWidth" value="4" />
<property name="headerType" value="unchecked" />
<property name="excludes" value="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck" />
</module>
</module>
IntelliJ IDEA 使用
Spring Javaformat 插件
-
从 Maven Central 下载 spring-javaformat-intellij-idea-plugin-0.0.39.jar
-
IntelliJ IDEA | Settings | Plugins | Install Plugin from Disk... 选择刚刚下载的 jar 文件,安装 Plugin
-
如果编辑器状态栏显示
图标,表示 Spring Formatter 正常启用
CheckStype-IDEA 插件
-
下载安装插件 https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
-
IntelliJ IDEA | Settings | Tools | Checkstyle 设置
- Checkstyle version: 9.3
- Configuration File Add
config/checkstyle/checkstyle.xml
- Third-Party Checks Add
spring-javaformat-checkstyle-0.0.39.jar
&&spring-javaformat-config-0.0.39.jar