2013-08-21 38 views
5

搖籃1.6 Linux操作系統。搖籃PMD的Checkstyle FindBugs的 - 這sourceSet目錄工作Java構建

Java構建項目結構

  • Project_or_Module
    • SRC/JAVA(包含Java源代碼)
    • 測試/ JAVA(包含JUnit測試 - 單元測試)
    • SRC/Java的測試(包含集成測試)
    • 等的/ 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這個乾淨的構建」或「gradle這個乾淨的構建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真正PMD 。錯誤說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

C.如何在build.gradle文件(非ANT)中使用包括/排除Checkstyle/PMD/Findbugs。 即它會不會去和做多「的src/java的」文件夾中的任何其他。

謝謝。

回答

10

下所做的所有問題的伎倆,除了B(問題2)即增加了sourceSets線,並告訴這3個工具(PMD /的CheckStyle/FindBugs的),只能看到主(源代碼,這是「SRC/JAVA 「)在sourceSets定義下。順便說一下,我採用了「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] 
    } 
+0

上面的代碼只是做了checkstyle/findbugs/pmd - 只檢查src/java(這是我的sourceSets.main)。除此之外,我的問題1的錯誤,在包含/提到build.gradle文件中的項目/模塊級別的相關jar名稱後得到解決。關於Xvfb插件的第二個錯誤或問題,通過在Jenkins中刪除Xvfb插件,重新啓動jenkins並最終清理工作區,即刪除了所有inder jenkins實例/作業/ /workspace/....級別 –