我已经安装了 google-java-format 插件并将以下 checkstyle 放入 config/checkstyle/checkstyle.xml 中:
https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
我的 build.gradle 看起来像这样:
plugins {
id 'org.springframework.boot' version '2.5.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'checkstyle'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
因此,当我运行任务 checkstyleMain 时,出现以下错误消息:
Document root element "code_scheme", must match DOCTYPE root "null".
有人可以帮忙吗?
Google Checkstyle 和 Google code-style 略有不同,并且格式不同。这就是您收到错误消息的原因。
从你的问题来看,我想你想配置IntelliJ代码风格插件。
您可以从这里下载codestyle xml。然后打开 IntelliJ,转到文件 → 设置 → 编辑器 → 代码样式。单击带有工具提示的齿轮图标,其中显示
Show Scheme Actions
,然后选择 Import Scheme
-> IntelliJ IDEA code style XML
。选择您下载的文件。如果有打开的弹出窗口,请确保勾选 Current scheme
。
更多细节提到这里