我将 Spotless 与 Gradle 一起使用。我已将其配置以使用 Eclipse 的 JDT 代码格式化程序:
spotless {
groovyGradle {
greclipse("4.21.0").configFile("${rootDir}/config/spotless/eclipe_groovy_formatter.xml")
}
java {
eclipse("4.21.0").configFile("${rootDir}/config/spotless/eclipe_jdt_formatter.xml")
endWithNewline()
importOrder("", "javax", "java")
indentWithSpaces(2)
lineEndings(LineEnding.UNIX)
removeUnusedImports()
trimTrailingWhitespace()
}
}
eclipe_jdt_formatter.xml
的内容就是:
<?xml version="1.0" encoding="UTF-8" ?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="Fulgore Team" version="12">
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="80" />
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="false" />
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert" />
</profile>
</profiles>
问题是我想在(Eclipse)XML 文件中配置正确的设置,以便使
enum
值各占一行。
例如,这就是当前格式化源代码的方式:
public enum Type {
VALUE, OTHER, ANOTHER,
}
...但我想要:
public enum Type {
VALUE,
OTHER,
ANOTHER,
}
如果有人知道我可以在 XML 文件中使用的设置组合来完成此任务,我将非常感激。我尝试了
.formatter
和/或 .indent
的几种组合,但没有运气。
尝试
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="49"/>