当前位置: 首页 > 知识库问答 >
问题:

Gradle PMD Checkstyle Findbugs-工作Java构建的源集目录

萧德馨
2023-03-14
    null
   apply plugin: 'java'
   apply plugin: 'pmd'
   apply plugin: 'findbugs'
   apply plugin: 'checkstyle'
   apply plugin: 'code-quality'
   apply plugin: 'jacoco'

   tasks.withType(Compile) {
     options.debug = true
     options.compilerArgs = ["-g"]
   }

   checkstyle {
        configFile = new File(rootDir, "config/checkstyle.xml")
        ignoreFailures = true
   }


   findbugs {
        ignoreFailures = true
   }

   pmd {
        ruleSets = ["basic", "braces", "design"]
        ignoreFailures = true
   }

   jacoco {
      toolVersion = "0.6.2.201302030002"
      reportsDir = file("$buildDir/customJacocoReportDir")
   }

   sourceSets {
      main {
         java {
            srcDir 'src/java'
         }
      }
      test {
         java {
            srcDir 'test/java'
         }
      }
      integrationTest {
         java {
            srcDir 'src/java-test'
         }
      }
   }

   test {
        jacoco {
            append = false
            destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
            classDumpFile = file("$buildDir/jacoco/classpathdumps")
        }
   }

   jacocoTestReport {
         group = "Reporting"
         description = "Generate Jacoco coverage reports after running tests."
         reports {
                xml{
                    enabled true
                    destination "${buildDir}/reports/jacoco/jacoco.xml"
                }
                csv.enabled false
                html{
                    enabled true
                    destination "${buildDir}/jacocoHtml"
                }
        }
        additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
   }
       apply plugin: 'java'
//   apply plugin: 'pmd'
//   apply plugin: 'findbugs'
//   apply plugin: 'checkstyle'
//   apply plugin: 'code-quality'
   apply plugin: 'jacoco'

   tasks.withType(Compile) {
     options.debug = true
     options.compilerArgs = ["-g"]
   }

//   checkstyle {
//        configFile = new File(rootDir, "config/checkstyle.xml")
//        ignoreFailures = true
//   }


//   findbugs {
//       ignoreFailures = true
//   }

//   pmd {
//        ruleSets = ["basic", "braces", "design"]
//        ignoreFailures = true
//   }
//

   jacoco {
      toolVersion = "0.6.2.201302030002"
      reportsDir = file("$buildDir/customJacocoReportDir")
   }

   sourceSets {
      main {
         java {
            srcDir 'src/java'
         }
      }
      test {
         java {
            srcDir 'test/java'
         }
      }
      integrationTest {
         java {
            srcDir 'src/java-test'
         }
      }
   }

   test {
        jacoco {
            append = false
            destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
            classDumpFile = file("$buildDir/jacoco/classpathdumps")
        }
   }

   jacocoTestReport {
         group = "Reporting"
         description = "Generate Jacoco coverage reports after running tests."
         reports {
                xml{
                    enabled true
                    destination "${buildDir}/reports/jacoco/jacoco.xml"
                }
                csv.enabled false
                html{
                    enabled true
                    destination "${buildDir}/jacocoHtml"
                }
        }
        additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
   }
..
....
:compileIntegrationTestJava
 /production/jenkinsAKS/jobs/Project_or_Module/workspace/src/java-test/com/tr/ids/application/project_or_module/Project_or_ModuleTestCase.java:11:
 package org.apache.cactus does not exist import
 org.apache.cactus.ServletTestCase;
                         ^ /production/jenkinsAKS/jobs/Project_or_Module/workspace/src/java-test/com/tr/ids/application/project_or_module/Project_or_ModuleTestCase.java:13:
> cannot find symbol symbol: class ServletTestCase public class
> Project_or_ModuleTestCase extends ServletTestCase
> 
 ...
  ....
  ..... 
  some more errors 
  ...
  ... 
  100 errors (similar errors).

b.其他项目之一ProjectAUtilities在PMD步骤失败,即使在PMD的Build.Gradle中忽略错误为true。错误表示有3个测试失败。

20:06:20 :pmdIntegrationTest UP-TO-DATE
20:06:21 :pmdMain
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/pmd/pmd/4.3/pmd-4.3.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/asm/asm/3.2/asm-3.2.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/asm/asm-parent/3.2/asm-parent-3.2.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/junit/junit/4.4/junit-4.4.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/xml-apis/xml-apis/1.3.02/xml-apis-1.3.02.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/pmd/pmd/4.3/pmd-4.3.jar
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/asm/asm/3.2/asm-3.2.jar
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/junit/junit/4.4/junit-4.4.jar
20:06:24 251 PMD rule violations were found. See the report at: file:///production/jenkinsAKS/jobs/ProjectAUtilities/workspace/build/reports/pmd/main.html
20:06:26 :pmdTest
20:06:26 16 PMD rule violations were found. See the report at: file:///production/jenkinsAKS/jobs/ProjectAUtilities/workspace/build/reports/pmd/test.html
20:06:26 :test
20:06:26 Download http://devserver2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.pom
20:06:26 Download http://devserver2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.build/0.6.2.201302030002/org.jacoco.build-0.6.2.201302030002.pom
20:06:27 Download http://devserver2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.jar
20:06:29 Xlib: connection to "localhost:13.0" refused by server
20:06:29 Xlib: PuTTY X11 proxy: wrong authorisation protocol attempted
20:06:29 
20:06:29 com.tr.ids.util.test.chart.TestChartUtilities > getPieChart FAILED
20:06:29     java.lang.InternalError at TestChartUtilities.java:89
20:06:29 
20:06:29 com.tr.ids.util.test.chart.TestChartUtilities > getLegend FAILED
20:06:29     java.lang.NoClassDefFoundError at TestChartUtilities.java:103
20:06:29 
20:06:29 com.tr.ids.util.test.chart.TestChartUtilities > useString FAILED
20:06:29     java.lang.NoClassDefFoundError at TestChartUtilities.java:143
20:06:29 
20:06:29 140 tests completed, 3 failed
20:06:29 :test FAILED
20:06:29 
20:06:29 FAILURE: Build failed with an exception.
20:06:29 
20:06:29 * What went wrong:
20:06:29 Execution failed for task ':test'.
20:06:29 > There were failing tests. See the report at: file:///production/jenkinsAKS/jobs/ProjectAUtilities/workspace/build/reports/tests/index.html
20:06:29 
20:06:29 * Try:
20:06:29 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
20:06:29 
20:06:29 BUILD FAILED

c.如何在build.gradle文件(而不是ANT)中为checkstyle/pmd/findbugs使用include/exclude。即除了“src/java”文件夹之外,它不会去做任何事情。

多谢了。

共有1个答案

高兴贤
2023-03-14
   checkstyle {
        configFile = new File(rootDir, "config/checkstyle.xml")
        ignoreFailures = true
        sourceSets = [sourceSets.main]
   }


   findbugs {
        ignoreFailures = true
        sourceSets = [sourceSets.main]
   }

   pmd {
        ruleSets = ["basic", "braces", "design"]
        ignoreFailures = true
        sourceSets = [sourceSets.main]
   }
 类似资料:
  • 你可以通过 sourceSets 属性来使用资源设置. 它其实是一个项目资源设置的容器, 它的类型是 SourceSetContainer. 同时也有 sourceSets { } 脚本模块, 在这个模块里, 你可以通过闭包配置资源设置容器. 资源设置容器的工作方式和其余容器几乎一模一样, 比如 tasks. 例 22.3. 进入资源设置 build.gradle // Various ways

  • 为什么Eclipse在构建一个Android项目时,会陷入构建工作区的无限循环...和(重新)构建工作区...和(重新)构建工作区... 这是已知的虫子吗? 走出这个循环的正确方法是什么? 备注: 如果取消选中,它会生成良好的版本,甚至导出一个完美运行的签名发行版APK。 此问题仅在我升级到最新的SDK r19后才开始。在此之前(SDK r11),我从未遇到过此问题。 错误160868正好描述了这

  • 现在让我们看一个典型的多项目构建. 下面是项目的布局: Example 7.10. 多项目构建 - 分层布局 构建布局 multiproject/ api/ services/webservice/ shared/ 注意: 这个例子的代码可以在 samples/java/multiproject 里找到. 现在我们能有三个项目. 项目的应用程序接口 (API) 产生一个 JAR 文件,

  • 22.7.2.定义一个新的 source set 要定义一个新的源组, sourceSets {} 块中引用它.下面是一个例子: 例22.5.定义一个新的 source set build.gradle sourceSets { intTest } 当你定义一个新的 source set, java 插件会为该 source set 添加一些如Table 22.6, “Java plugi

  • 22.7.3.一些 source set 的例子 加入含有类文件的 sorce set 的 JAR: 例22.8.为 source set 组装 JAR build.gradle task intTestJar(type: Jar) { from sourceSets.intTest.output } 为 source set 生成 javadoc: 例22.9.为 source set

  • 22.7.1.Source Set 属性 下表列出了 Source Set 的一些重要属性, 更多细节请查看 SourceSet 的 API 文档. 表22.9.java 插件- Source Set 属性 配置名称 类型 默认值 描述 name String (read-only) Not null 用来识别source set的名称 output SourceSetOutput(read-on