0

Google Java フォーマット スタイルでスポットレスを使用するように Maven スプリング ブート アプリケーションを構成しようとしています。mavenプラグインと同じように、Intellijがコードをフォーマットすることも望んでいます。

しかし、適用されるフォーマットが少し異なることに気付きました。

一例: Intellij は次の 2 行を変更しません。

@Mock 
private UserRepository userRepositoryMock;

ただし、maven プラグイン (コマンド mvn spotless:apply を使用) は次のようにフォーマットされます。

@Mock private UserRepository userRepositoryMock;

POM 構成

<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 から次のコード スタイルを追加しました

Github サイト https://github.com/google/google-java-format

IntelliJ Java Google スタイル ファイル https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml

Intellij コード スタイル ウィンドウ

なぜ違いがあるのですか?他に何が違うでしょうか?Intellij でコードを Google Java コード スタイル形式の xml ファイルとまったく同じようにフォーマットするにはどうすればよいですか?

事前にご協力いただきありがとうございます

よろしく

4

0 に答える 0