用于自动格式化代码以匹配 google checkstyle 的 Maven 插件?

Joh*_*son 1 java checkstyle maven

我在 Intellij 中使用 google checkstyle:https : //github.com/google/styleguide

当我在 IntelliJ 中进行任何编码期间进行格式化时,我运行了这个 eclipse checkstyle,它似乎工作正常。我想要一个 Maven 阶段,每当我运行mvn clean install.

我正在使用以下插件:

<plugin>
    <groupId>net.revelc.code.formatter</groupId>
    <artifactId>formatter-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>format</goal>
            </goals>
            <configuration>
                <configFile>src/main/resources/eclipse-java-google-style.xml</configFile>
                <encoding>UTF-8</encoding>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

不幸的是,它似乎没有正确注册该配置文件。我想知道获取正确的 checkstyle 配置的最佳经验法则是什么。我把它放在哪里以及如何在我的 POM 中表示它?

Gui*_*lem 11

根据formatter-maven-plugin文档的示例“使用外部资源的基本配置”,您必须删除中的“src/main/resources/”:

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
    <execution>
        <goals>
            <goal>format</goal>
        </goals>
        <configuration>
            <configFile>eclipse-java-google-style.xml</configFile>
            <encoding>UTF-8</encoding>
        </configuration>
    </execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

  • Ryan,如果它确实解决了您的问题,请您接受答案吗? (4认同)