1

maven checkstyle 插件告诉我它sun_checks.xml默认使用:

INFO] There are 5 errors reported by Checkstyle 8.29 with sun_checks.xml ruleset.

我的意思是,我没有sun_checks.xml在我的项目中找到任何东西来告诉 checkstyle 插件使用这个文件。

所以,我猜,插件默认有这个文件。

根据文档,插件默认有两个可用的检查规则集:sun_checks.xmlgoogle_checks.xml.

我试图改变它:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${checkstyle-plugin.version}</version>
            <configuration>
                <configLocation>google_checks.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>
</reporting>

执行mvn checkstyle:check目标后,它告诉我它正在使用sun_checks.xml而不是google_checks.xml

$ mvn checkstyle:check
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< net.gencat.clt.arxius:backend >--------------------
[INFO] Building backend 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-checkstyle-plugin:3.1.1:check (default-cli) @ backend ---
[INFO] There are 4 errors reported by Checkstyle 8.29 with sun_checks.xml ruleset.
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[1] (javadoc) JavadocPackage: Missing package-info.java file.
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[6,1] (design) HideUtilityClassConstructor: Utility classes should not have a public or default constructor.
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[9,1] (whitespace) FileTabCharacter: File contains tab characters (this is the first instance).
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[9,9] (javadoc) MissingJavadocMethod: Missing a Javadoc comment.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.265 s
[INFO] Finished at: 2020-10-21T10:45:52+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (default-cli) on project backend: You have 4 Checkstyle violations. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

有任何想法吗?

4

1 回答 1

2

您正在使用<reporting>标签下的 google_checks.xml。你可以像这样保留它,但是像 maven.apache.org 所说的 repoting 标记插件实际上本身并不是一个报告插件。但是它的一个(或几个)目标或 Mojo 可能专门由 maven-site-plugin 调用,通常在站点构建生命周期中调用。

如果你想使用 mvn checkstyle:check 目标,你还需要:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.17</version>
            <executions>
                <execution>
                    <id>checkstyle</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <configLocation>google_checks.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>
</build>
于 2020-10-22T12:26:54.373 回答