【问题标题】:Checkstyle checkstyle-checker.xml gets overriden when multiple configs are used使用多个配置时,Checkstyle checkstyle-checker.xml 会被覆盖
【发布时间】:2021-08-23 00:40:07
【问题描述】:

我需要分离用于生产和测试源代码的 checkstyle 插件配置。 我设法做到了(参见下面的配置),但是有一个“checkstyle-checker.xml”文件始终被覆盖并保留在目标目录的根目录中。

  1. 有没有办法将它移动到 /target/checkstyle 目录?
  2. 有没有办法将它在 prod 和 test 源代码之间分开?

<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
    <encoding>${project.build.sourceEncoding}</encoding>
    <consoleOutput>true</consoleOutput>
    <failsOnError>true</failsOnError>
    <failOnViolation>${maven-checkstyle-plugin.failOnViolation}</failOnViolation>
    <logViolationsToConsole>${maven-checkstyle-plugin.logViolationsToConsole}</logViolationsToConsole>
    <violationSeverity>warning</violationSeverity>
    <linkXRef>true</linkXRef>
    <skip>${maven-checkstyle-plugin.skip}</skip>
</configuration>
<executions>
    <execution>
        <id>checkstyle-validate</id>
        <phase>validate</phase>
        <goals>
            <goal>check</goal>
        </goals>
        <configuration>
            <sourceDirectories>${project.build.sourceDirectory}</sourceDirectories>
            <includeTestSourceDirectory>false</includeTestSourceDirectory>
            <configLocation>/checkstyle/checkstyle.xml</configLocation>
            <outputFile>${project.build.directory}/checkstyle/checkstyle-result.xml</outputFile>
            <cacheFile>${project.build.directory}/checkstyle/checkstyle-cache</cacheFile>
        </configuration>
    </execution>
    <execution>
        <id>checkstyle-validate-test</id>
        <phase>validate</phase>
        <goals>
            <goal>check</goal>
        </goals>
        <configuration>
            <sourceDirectories/>
            <testSourceDirectories>${project.build.testSourceDirectory}</testSourceDirectories>
            <includeTestSourceDirectory>true</includeTestSourceDirectory>
            <configLocation>/checkstyle/checkstyle-test.xml</configLocation>
            <outputFile>${project.build.directory}/checkstyle/checkstyle-result-test.xml</outputFile>
            <cacheFile>${project.build.directory}/checkstyle/checkstyle-cache-test</cacheFile>
        </configuration>
    </execution>
</executions>
<dependencies>
    <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>${maven-checkstyle-plugin.checkstyle.rules.version}</version>
    </dependency>
</dependencies>
</plugin>

【问题讨论】:

    标签: maven static-analysis checkstyle software-quality


    【解决方案1】:

    该文件似乎是由 maven-checkstyle-plugin 生成的,如 https://github.com/apache/maven-checkstyle-plugin/blob/6d229a74b4a7eb2efc5fce287d932f6b5c250647/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java#L733 所示

    查看https://github.com/apache/maven-checkstyle-plugin/blob/6d229a74b4a7eb2efc5fce287d932f6b5c250647/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java#L765 似乎无法覆盖它的位置,它总是会进入项目的构建目录。

    我不确定这个文件在插件的工作中起到什么作用,因为它不是基本 checkstyle 库的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 2013-11-10
      • 2019-08-30
      相关资源
      最近更新 更多