简体   繁体   English

Gradle 构建失败,出现错误 checkstyleMain FAILED

[英]Gradle build failes getting an error checkstyleMain FAILED

I recently upgraded my project.我最近升级了我的项目。

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

My project build fails and getting the error:我的项目构建失败并收到错误消息:

Task :checkstyleMain FAILED任务:checkstyleMain 失败

.gradle\\daemon\\4.10.2\\etc\\checkstyle\\checkstyle-suppressions.xml (The system cannot find the path specified) .gradle\\daemon\\4.10.2\\etc\\checkstyle\\checkstyle-suppressions.xml(系统找不到指定的路径)

Here is my gradle build file:这是我的 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'))
   }

Here is my project structure:这是我的项目结构: 在此处输入图片说明

Try to reference it alike this (these config XML can all be dropped into there):尝试像这样引用它(这些配置 XML 都可以放在那里):

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

The checkstyle-suppressions.xml should be found when declaring an absolute path.声明绝对路径时应找到checkstyle-suppressions.xml

Finally I got it working.最后我让它工作了。 Thanks for the hint Martin.感谢马丁的提示。

There was a totally different strategy when using java 11使用 java 11 时有一个完全不同的策略

Gradle checkstyle plugin searches for suppressions.xml within the daemon folder when using Java 11使用 Java 11 时,Gradle checkstyle 插件在守护程序文件夹中搜索抑制.xml

this post has helped me https://github.com/gradle/gradle/issues/8286这篇文章对我有帮助https://github.com/gradle/gradle/issues/8286

This is what I had to make in my project to make it work这是我必须在我的项目中制作才能使其工作的内容

In the build.gradle在 build.gradle

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

In checkstyle.xml在 checkstyle.xml

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM