Ant*_*gos 13 java intellij-idea spotless
我使用Spotless Gradle 插件来确保我的应用程序中 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()
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以配置 IntelliJ 以使用相同的格式设置吗?
小智 8
尽管 Tob 的方法有效,但我使用了一些不同的配置方式。
\n我更喜欢使用\xe2\x8c\x98+ \xe2\x8c\xa5+ ;,因为它很容易记住(IDEA默认使用\xe2\x8c\x98+ \xe2\x8c\xa5+ )。\nL
按\xe2\x8c\x98+ \xe2\x8c\xa5+;并等待所有文件都被处理并且 IDE 重新加载更改的文件。通常需要 2-5 秒。
警告:spotless 可能会崩溃(通常是由于代码错误而发生,因此请确保您的代码是可编译的):\n
一种不是 100% 令人满意但有效的方法:
1. 配置 Spotless 任务
spotless {
format 'misc', {
target '*.properties','*.gradle', '*.md', '.gitignore' // etc.
// code style rules
}
java {
// code style rules
}
}
Run Code Online (Sandbox Code Playgroud)
2.为*Apply任务添加任务激活
3. 分配方便的按键 Build Project
在Settings > Keymap.
请记住,这Build Project是使用 IntelliJ 的内部构建器。它是增量(性能),但在自定义/第三方 gradle 任务的情况下,构建结果可能会偏离$ gradle build结果。
对于使用 DevTools 的 Spring 应用程序,构建将导致自动提供更改/更新。
使用 IDE Hook,为 IntelliJ 实现专用的 Spotless 格式化程序插件应该很简单:https : //github.com/diffplug/spotless/blob/master/plugin-gradle/IDE_HOOK.md
到目前为止,我无法找到一个。
| 归档时间: |
|
| 查看次数: |
4695 次 |
| 最近记录: |