mvn checkstyle插件:google_checks未达到

huangapple go评论79阅读模式
英文:

mvn checkstyle plugin: google_checks no reached

问题

maven checkstyle 插件默认使用 sun_checks.xml

INFO] 使用 Checkstyle 8.29 和 sun_checks.xml 规则集报告了 5 个错误。

我的意思是,我在项目中没有找到任何 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] 扫描项目中...
[INFO] 
[INFO] -------------------< net.gencat.clt.arxius:backend >--------------------
[INFO] 构建 backend 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-checkstyle-plugin:3.1.1:check (default-cli) @ backend ---
[INFO] 使用 Checkstyle 8.29 和 sun_checks.xml 规则集报告了 4 个错误。
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[1] (javadoc) JavadocPackage:缺少 package-info.java 文件。
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[6,1] (design) HideUtilityClassConstructor:实用程序类不应具有公共或默认构造函数。
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[9,1] (whitespace) FileTabCharacter:文件包含制表符字符(这是第一个实例)。
[ERROR] src/main/java/net/gencat/clt/arxius/backend/BackendApplication.java:[9,9] (javadoc) MissingJavadocMethod:缺少 Javadoc 注释。
[INFO] ------------------------------------------------------------------------
[INFO] 构建失败
[INFO] ------------------------------------------------------------------------
[INFO] 总时间:1.265 秒
[INFO] 完成于:2020-10-21T10:45:52+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] 无法执行目标 org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check(default-cli),项目 backend:有 4 个 Checkstyle 违规。-> [Help 1]
[ERROR] 
[ERROR] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。
[ERROR] 使用 -X 开关重新运行 Maven 以启用完整调试日志记录。
[ERROR] 
[ERROR] 有关错误和可能的解决方案的更多信息,请阅读以下文章:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

有什么想法吗?

英文:

maven checkstyle plugin is telling me that it's using sun_checks.xml by default:

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

I mean, I've not located any sun_checks.xml into my project in order to tell checkstyle plugin to use this file.

So, I guess, plugin has available this file by default.

According to documentation, plugin has available two check rulesets by default: sun_checks.xml and google_checks.xml.

I've tried to change it:

&lt;reporting&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
            &lt;version&gt;${checkstyle-plugin.version}&lt;/version&gt;
            &lt;configuration&gt;
                &lt;configLocation&gt;google_checks.xml&lt;/configLocation&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/reporting&gt;

After performing mvn checkstyle:check goal, it's telling me that it's using sun_checks.xml instead of google_checks.xml:

$ mvn checkstyle:check
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------&lt; net.gencat.clt.arxius:backend &gt;--------------------
[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. -&gt; [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

Any ideas?

答案1

得分: 2

你正在使用<reporting>标签下的google_checks.xml。你可以保持这样,但是根据maven.apache.org所述:插件本身实际上并不是报告插件。但是它的一个或多个目标(goals)或 Mojos 可能被专门设计成由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>
英文:

You are using the google_checks.xml under &lt;reporting&gt; tag. You can keep it like this but repoting tag as maven.apache.org says: A plugin is actually not a report plugin in itself. But one (or several) of its goals or Mojos may be specialized to be invoked by maven-site-plugin, typically during the site build life cycle.

if you want to use mvn checkstyle:check goal you need to also have:

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.17&lt;/version&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;id&gt;checkstyle&lt;/id&gt;
                    &lt;phase&gt;validate&lt;/phase&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;check&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
            &lt;configuration&gt;
                &lt;configLocation&gt;google_checks.xml&lt;/configLocation&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

huangapple
  • 本文由 发表于 2020年10月21日 16:49:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64460036.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定