我使用Spotless Gradle plugin来确保应用程序中Java代码的格式一致。build.gradle
中的相关条目包括
plugins {
id "com.diffplug.gradle.spotless" version "3.27.0"
}
spotless {
java {
// The available versions of the Eclipse JDT formatter are defined here
// https://github.com/diffplug/spotless/tree/master/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter
eclipse('4.13.0')
indentWithSpaces()
removeUnusedImports()
}
}
是否可以通过某种方式将IntelliJ配置为使用相同的格式设置?
发布于 2020-10-11 17:50:38
一种不是100%令人满意但有效的方法:
1.配置无斑点任务
spotless {
format 'misc', {
target '*.properties','*.gradle', '*.md', '.gitignore' // etc.
// code style rules
}
java {
// code style rules
}
}
2.将任务激活添加到 *Apply
tasks
3.为 Build Project
分配方便的击键
在Settings > Keymap
下执行此操作。
请记住,Build Project
使用的是IntelliJ的内部构建器。它是增量的(性能),但在自定义/第三方gradle任务的情况下,构建结果可能会偏离$ gradle build
结果。
在Spring应用程序使用DevTools的情况下,构建将导致自动提供更改/更新。
使用IDE Hook,为IntelliJ实现一个专用的无Spotless格式化程序插件应该是相当简单的:https://github.com/diffplug/spotless/blob/master/plugin-gradle/IDE_HOOK.md
不过到目前为止,我还没能找到一个。
https://stackoverflow.com/questions/59754621
复制相似问题