【问题标题】:Checkstyle - non deterministic check resultCheckstyle - 非确定性检查结果
【发布时间】:2014-02-19 10:02:43
【问题描述】:

我有一个大型 JEE Maven 多模块项目,并通过 build-tools 模块为 Checkstyle 共享一组自定义规则和抑制。由于对同一模块的测试,我发现很难发布此构建工具的稳定版本。

每次我运行一个 Maven 阶段,我都会得到不同的执行结果。

这是父 pom.xml 中的 Checkstyle 配置:

<build>    
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${checkstyle.plugin.version}</version>
        <configuration>
          <skip>${skipQATests}</skip>
          <configLocation>qa/checkstyle_rules.xml</configLocation>
          <propertiesLocation>${checkstyleDir}/checkstyle.properties</propertiesLocation>
          <suppressionsLocation>qa/suppressions.xml</suppressionsLocation>
          <encoding>UTF-8</encoding>
          <consoleOutput>true</consoleOutput>
          <failsOnError>true</failsOnError>
          <failOnViolation>true</failOnViolation>
          <linkXRef>false</linkXRef>
        </configuration>
        <executions>
          <execution>
             <id>checkstyle-compile</id>
             <phase>compile</phase>                     
             <goals>
            <goal>check</goal>
             </goals>
          </execution>
        </executions>
    </plugin>
  </plugins>
</build>

我正在尝试在执行中找到一种模式,项目在一项特定检查中设置为失败,我找不到“错误”。

  1. 我执行了编译 maven 阶段 (mvn clean compile),但在给定的检查中失败。
  2. 我执行包 maven 阶段 (mvn clean package) 也失败了。
  3. 我再次执行编译阶段(mvn clean compile)并且它没有失败(所有成功)
  4. 我再次执行包失败
  5. 它不会在几次运行中失败,然后在某些不同的执行中再次失败

我知道如果没有所有项目信息,这种行为很难追踪。但是是否有任何类型的程序、日志、工具可以提供有关调试此问题的更多信息,以便我可以确定它是错误还是配置错误??

提前致谢!!

更新:

我刚刚在我正在测试 Checkstyle 的子模块上执行了两次相同的 mvn 命令(强制违反规则的测试)-mvn checkstyle:check -X

结果彼此不同,主要区别在于正确的执行(构建失败的那个在第一次尝试时没有找到文件)和错误的执行(以成功结束的那个找到配置文件第一次尝试)

EXEC_1: ...

[DEBUG] The resource 'qa/suppressions.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.    
[DEBUG] The resource 'qa/suppressions.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/suppressions.xml.    
[DEBUG] Adding the outputDirectory file:/C:/LAB/PRJ/prj-ejbws/target/classes/ to the Checkstyle class path    
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.    
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/checkstyle_JEE.xml.    
[DEBUG] The resource 'ubic.properties' was found as C:\LAB\PRJ\ubic.properties.

[INFO] Starting audit...    
[INFO] --------------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------------
[INFO] Total time: 1.542s
[INFO] Finished at: Thu Feb 20 16:35:22 CET 2014
[INFO] Final Memory: 8M/20M
[INFO] --------------------------------------------

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.11:check (default-cli) on project GestionDelContacto-opsa-ejbws: Failed during checkstyle execution: There are 2 checkstyle errors. 

EXEC_2:...

[DEBUG] The resource 'qa/suppressions.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/suppressions.xml.    
[DEBUG] Adding the outputDirectory file:/C:/LAB/PRJ/prj-ejbws/target/classes/ to the Checkstyle class path    
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/checkstyle_JEE.xml.    
[DEBUG] The resource 'ubic.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader.    
[DEBUG] The resource 'ubic.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.    
[DEBUG] The resource 'ubic.properties' was found as C:\LAB\PRJ\ubic.properties.

[INFO] Starting audit...

[INFO] --------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------
[INFO] Total time: 1.570s
[INFO] Finished at: Thu Feb 20 16:37:05 CET 2014
[INFO] Final Memory: 8M/20M
[INFO] ---------------------------------------------

有什么线索吗?

【问题讨论】:

  • 失败是什么意思?您收到错误消息吗?您是否尝试过使用 -X -e 选项运行 maven 以获得更详细的输出?
  • 当我说失败时,我的意思是:Checkstyle 检测到违反规则并中断构建。我整个早上都在研究这个问题,发现了以下问题: - Plexus 资源加载器是在某些 mvn 执行中不使用插件配置上的 propertiesLocation 标记加载 checkstyle 属性文件的那个,所以当 checkstyle 启动时它不会加载属性以在我的非法进口检查中进行 propertyExpansion。
  • 您是否尝试过位置路径的固定值而不是 POM 中的变量?您还应该检查项目中的变量是否设置正确。如果变量在子项目之间继承,尤其是多模块项目往往会遇到问题。
  • 我将值更改为固定,但没有变化。它保持上述行为。有时有效,有时无效。 -X 执行为我正在加载的文件(配置、抑制、属性)返回此日志[DEBUG] The resource 'ubicacion.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.URLResourceLoader. [DEBUG] The resource 'ubicacion.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader. [DEBUG] The resource 'ubicacion.properties' was found as C:\LAB\PRJ\ubicacion.properties.
  • 还是没有运气。我遇到了同样的问题,我无法找到错误...

标签: java maven runtime checkstyle


【解决方案1】:

停止使用 Maven,单独运行 CheckStyle。您已经掌握了足够的“线索”:有时 Maven 正确初始化 CheckStyle,有时未正确初始化,并且依赖于不可靠的基础设施是个坏主意。

【讨论】:

    猜你喜欢
    • 2012-09-09
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多