Gradle PMD Checkstyle Findbugs - 用于Java构建的sourceSet目录

时间:2013-08-21 19:03:49

标签: gradle ignore findbugs checkstyle pmd

Gradle 1.6 Linux。

Java构建项目结构

  • Project_or_Module
    • src / java(包含java源代码)
    • test / java(包含JUnit测试 - 单元测试)
    • src / java-test(包含集成测试)
    • etc / etc(项目下的其他.. ..文件夹)

我有以下全局配置/ build.gradle文件:

   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)
   }

对于少数项目,一切正常。 即当我运行“gradle clean build”或“gradle clean build jacocoTestReport”时,一切都会成功。

对于其他一些项目,我看到以下问题并需要帮助。

1)如果我删除/注释掉项目的以下行,则“ gradle clean build ”命令有效。但是当这些行在上面显示的代码快照中被取消注释时,我会看到错误。代码快照后面会提到错误。

       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)
   }

错误: A.任务失败。输出显示以下内容。

..
....
: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).

你会注意到,当Gradle为“src / java-test”文件夹调用上述任务时,错误就会出现。

**我的问题1 **:在build.gradle文件中注释了这些行,我从未看到这些错误并且“clean build jacocoTestReport”任务成功完成,但是当启用了pmd / findbugs / checkstyle的代码时,我看到了这些错误。为什么它编译java测试代码。我认为源代码只在src / java下(项目的实际java源代码:project_or_module)

B中。其中一个项目ProjectAUtilities在PMD步骤失败,即使在build.gradle for pmd中忽略ignore错误。错误说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

我的问题2 :我应该为build.gradle中的PMD部分设置哪些配置,如果失败则忽略测试。我想我已经有了 ignoreFailures = true

℃。如何在build.gradle文件(而不是ANT)中使用Checkstyle / PMD / Findbugs的include / exclude。    即除了“src / java”文件夹之外,它不会去做任何事情。

感谢。

1 个答案:

答案 0 :(得分:10)

以下为所有问题解决了问题除了B(问题2),即添加了一个sourceSets行并告诉这3个工具(pmd / checkstyle / findbugs)只看到main(源代码是sourceSets定义下的“src / java”)。顺便说一句,我采用了“sourceSets”部分,并在以下行之前定义了它。

   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]
   }