创建定制版本的Google Java Checkstyle XML文件

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

Creating a customized version of the Google Java Checkstyle XML file

问题

我目前正在尝试创建一个基于Google代码风格的Checkstyle样式表,但会有一些小的调整(如新行长度和缩进长度)。我从Github(https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml)上获取了这个文件,但在运行时遇到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (default-cli) on project some-api: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check failed: given name COMPACT_CTOR_DEF -> [Help 1]

Maven插件配置:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${checkstyle-maven-plugin.version}</version>
        <configuration>
          <consoleOutput>true</consoleOutput>
          <configLocation>google_checks1.xml</configLocation>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

是否需要包含一些依赖项?有更好的实现方法吗?非常感谢您的任何反馈。

英文:

I am currently trying to create a checkstyle stylesheet that is based off of the Google one, but with some minor tweaks (new line length and indentation lengths. I grabbed this file off of Github (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml), but I am getting the following error when I run it:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (default-cli) on project some-api: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check failed: given name COMPACT_CTOR_DEF -&gt; [Help 1]

Maven plugin configuration:

      &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-maven-plugin.version}&lt;/version&gt;
        &lt;configuration&gt;
          &lt;consoleOutput&gt;true&lt;/consoleOutput&gt;
          &lt;configLocation&gt;google_checks1.xml&lt;/configLocation&gt;
        &lt;/configuration&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;check&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;

Are there some dependencies that I need to include? Is there a better way of achieving my goal? Any feedback would be appreciated.

答案1

得分: 3

以下是翻译好的内容:

上面的评论提供了解决此问题的方法。
需要包含依赖项以指定用于 Maven 插件的 checkstyle 版本。

以下内容对我有效,修复了从复制的 Google 检查中出现的 COMPACT_CTOR_DEF 错误。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.1.1</version>
    <dependencies>
        <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>8.36</version>
        </dependency>
    </dependencies>
    <configuration>
        <configLocation>my_checks.xml</configLocation>
    </configuration>
</plugin>
英文:

The comment above gives the way to fix this issue.
Need to include the dependency to specify the checkstyle version for the maven plugin.

The following worked for me, fixing the COMPACT_CTOR_DEF error from the copied google checks

&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;3.1.1&lt;/version&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.puppycrawl.tools&lt;/groupId&gt;
            &lt;artifactId&gt;checkstyle&lt;/artifactId&gt;
            &lt;version&gt;8.36&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;

    &lt;configuration&gt;
        &lt;configLocation&gt;my_checks.xml&lt;/configLocation&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年9月12日 02:53:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63852780.html
匿名

发表评论

匿名网友

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

确定