2015-11-10 84 views
0

我使用gradle中的sonar-runner插件調用sonar。我也在使用重用報告標誌。 如何從所有分析中排除所有測試類(Checkstyle,Findbugs,Coverage)?從gradle中排除所有分析的測試類

我目前使用下面的插件配置

sonarRunner { 
sonarProperties { 
    property "sonar.host.url", "<HOST>" 

    property "sonar.scm.disabled", "true" 
    property "sonar.login", "<USER>" 
    property "sonar.password", "<password>" 

    property "sonar.sources", "src" 
    property "sonar.exclusions", "**/test/**/*.java" 
    property "sonar.projectVersion", project.releaseDisplayName 
    // these should not change anything as sonar uses the defaults set for gradle 
    //property "sonar.tests", "test" 
} 

我的源集如下:

sourceSets { 
main { 
    java { 
     srcDir 'src' 
     srcDir 'src-gen' 
    } 
} 
test { 
    java { srcDir 'test' } 
} 

感謝

+0

你到目前爲止試過的任何東西?你目前如何配置源代碼集?顯示你的插件配置。 – RaGe

+0

我的配置是這樣的: sonarRunner { \t sonarProperties { \t \t財產 「sonar.host.url」, 「」 \t \t \t \t財產 「sonar.scm.disabled」, 「真」 \t \t財產 「sonar.login」, 「」 \t \t財產 「sonar.password」, 「」 \t \t財產「兒子ar.sources」, 「SRC」 \t \t財產 「sonar.exclusions」, 「** /測試/ **/*。java的」 \t \t財產 「sonar.projectVersion」,project.releaseDisplayName \t \t //這些聲納用來設置的gradle \t \t //財產「sonar.tests」的默認設置,「測試」應該不會改變任何東西 \t}} 如何 – user1587852

+0

是你sourcesets設置? – RaGe

回答

0

試試這個:

jacocoTestReport { 
     afterEvaluate { 
       sourceDirectories = files(sourceDirectories.files.collect { 
       fileTree(dir: it, exclude: [ 'com/path/to/package/that/I/want/to/exclude/are/inside/thisfolder_or_dto/**' ]) 
       }) 
       classDirectories = files(classDirectories.files.collect { 
       fileTree(dir: it, exclude: [ 'com/path/to/package/that/I/want/to/exclude/are/inside/thisfolder_or_dto/**' ]) 
       }) 
     } 
} 

sonarRunner { 
    sonarProperties { 
     property "sonar.exclusions", "com/path/to/package/that/I/want/to/exclude/are/inside/thisfolder_or_dto/**" 
    } 
} 

    //Required with Gradle 2.0+ -- 2.0+ -- 2.3 
    pmd { 
     ruleSets = ["java-basic", "java-braces", "java-design" ] 
     ignoreFailures = true 
    } 

    codenarc { 
    ignoreFailures = true 
    //The following file should exist or build will fail, you can find one online a sample version 
    configFile = file("config/codenarc/codenarc.xml") 
    } 


    checkstyle { 
     configFile = new File(rootDir, "config/checkstyle.xml") 
     ignoreFailures = true 
     //sourceSets = [sourceSets.main, sourceSets.test, sourceSets.integrationTest] 

     //Just run checkstyle only on main source code 
     sourceSets = [sourceSets.main] 
    } 


    findbugs { 
     ignoreFailures = true 
     //Just run findbugs only on main source code 
     sourceSets = [sourceSets.main] 

     //You can use if statement in groovy to set which toolVersion 2.0.3 or 3.0.1 depending upon JAVA version used in the project 
     toolVersion = "3.0.1" 
    } 

辛非常,您可以直接在測試或測試任務的jacoco部分中使用排除屬性。

def generatedSources = ['com/yahoo/**', 'com/amazon/**'] 

    test { 
     jacoco { 
       excludes = generatedSources 
     } 
    } 

    jacocoTestReport { 
     doFirst { 
       classDirectories = fileTree(dir: "${buildDir}/classes/main/").exclude(generatedSources) 
     } 
     reports { 
       xml.enabled true 
     } 
    } 

雖然發佈到SonarQube(sonar.exclusions =值應爲從工作區的相對即SRC/JAVA/COM/.../...)