【问题标题】:Gradle build failes getting an error checkstyleMain FAILEDGradle 构建失败,出现错误 checkstyleMain FAILED
【发布时间】:2019-07-29 21:11:31
【问题描述】:

我最近升级了我的项目。

   spring boot: 2.1.6 
   gradle: 4.10.2 
   java version 11
   jacoco : 0.8.1
   checkstyle: 8.1

我的项目构建失败并出现错误:

任务:checkstyleMain FAILED

.gradle\daemon\4.10.2\etc\checkstyle\checkstyle-suppressions.xml(系统找不到指定的路径)

这是我的 gradle 构建文件:

    jacoco {
       toolVersion = '0.8.1'
    }

    jacocoTestReport {
        afterEvaluate {
           classDirectories = files(classDirectories.files.collect {
                fileTree(dir: it, exclude: [
                       'com/emp/contacts/domain', 
  'com/emp/MyApplication.class'
               ])
           })
       }
   }

   checkstyle {
       toolVersion = '8.1'
       configFile = new File(rootDir, 'etc/checkstyle/checkstyle.xml')
       System.setProperty('checkstyle.cache.file', String.format('%s/%s', 
       buildDir, 'checkstyle.cachefile'))
   }

这是我的项目结构:

【问题讨论】:

    标签: java gradle checkstyle


    【解决方案1】:

    尝试像这样引用它(这些配置 XML 都可以放入其中):

    configFile file("${project.rootDir}/config/checkstyle.xml")
    

    声明绝对路径时应找到checkstyle-suppressions.xml

    【讨论】:

    • @barfuin 把它们放在你想放的地方,config 目录不会那么混乱。
    【解决方案2】:

    我终于让它工作了。感谢马丁的提示。

    使用 java 11 时的策略完全不同

    Gradle checkstyle 插件在使用 Java 11 时在 daemon 文件夹中搜索 suppresss.xml

    这篇文章对我有帮助 https://github.com/gradle/gradle/issues/8286

    这是我必须在我的项目中进行的才能使其正常工作

    在 build.gradle 中

    checkstyle {
        configDir = file("$rootProject.projectDir/etc/checkstyle")  
    }
    

    在 checkstyle.xml 中

    <!-- Suppression file -->
    <module name="SuppressionFilter">
       <property name="file" value="${config_loc}/checkstyle-suppressions.xml"/>
    </module>
    

    【讨论】:

      猜你喜欢
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多