maven Spotless + Java Google格式vs Intellij +导入文件

xam8gpfp  于 6个月前  发布在  Maven
关注(0)|答案(1)|浏览(64)

我正试图配置一个maven spring Boot 应用程序使用一尘不染与谷歌java格式风格。我想以及有Intellij格式化的代码作为maven插件做。
但我注意到,应用的形式有点不同。
一个例子:Intellij不会更改以下两行

@Mock 
private UserRepository userRepositoryMock;

字符串
但是maven插件(使用命令:mvn spotless:apply)将像这样格式化:

@Mock private UserRepository userRepositoryMock;

POM CONFIG

<plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>${spotless.version}</version>
                <configuration>
                    <!-- optional: limit format enforcement to just the files changed by this feature branch -->
                    <ratchetFrom>origin/master</ratchetFrom>
                    <formats>
                        <!-- you can define as many formats as you want, each is independent -->
                        <format>
                            <!-- define the files to apply to -->
                            <includes>
                                <include>*.md</include>
                                <include>.gitignore</include>
                            </includes>
                            <!-- define the steps to apply to those files -->
                            <trimTrailingWhitespace/>
                            <endWithNewline/>
                            <indent>
                                <spaces>true</spaces>
                                <spacesPerTab>4</spacesPerTab>
                            </indent>
                        </format>
                    </formats>
                    <!-- define a language-specific format -->
                    <java>
                        <!-- no need to specify files, inferred automatically, but you can if you want -->
                        <importOrder>  <!-- or a custom ordering -->
                            <order>java,javax,org,com,microservices.book.multiplication,
                            </order>  <!-- or use <file>${project.basedir}/eclipse.importorder</file> -->
                            <!-- you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports -->
                        </importOrder>

                        <removeUnusedImports/> <!-- self-explanatory -->

                        <!-- apply a specific flavor of google-java-format and reflow long strings -->

                        <googleJavaFormat>
                            <version>1.14.0</version>
                            <style>GOOGLE</style>
                            <reflowLongStrings>true</reflowLongStrings>
                        </googleJavaFormat>
                        <indent>
                            <tabs>true</tabs>
                            <spacesPerTab>2</spacesPerTab>
                        </indent>
                        <indent>
                            <spaces>true</spaces>
                            <spacesPerTab>4</spacesPerTab>
                        </indent>
                    </java>
                </configuration>
            </plugin>

在Intellij上我添加了以下来自Google的代码stile
Github网站https://github.com/google/google-java-format
IntelliJ Java Google Style文件https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml


的数据
为什么会有差异?还有什么可能不同?我如何让Intellij将代码格式化为Google Java代码样式格式XML文件?
非常感谢你的帮助提前
问候

xv8emn3q

xv8emn3q1#

从文档中修复注解问题:

<!-- fixes formatting of type annotations, see below -->
<formatAnnotations />

字符串

相关问题