不包括gradle所有分析的测试类

不包括gradle所有分析的测试类,gradle,sonarqube,Gradle,Sonarqube,我正在使用gradle的sonar runner插件调用sonar。我还使用了重用报告标志。 如何从所有分析中排除所有测试类(Checkstyle、Findbugs、Coverage) 我目前正在使用以下插件配置: sonarRunner { sonarProperties { property "sonar.host.url", "<HOST>" property "sonar.scm.disabled", "true" property "sonar.l

我正在使用gradle的sonar runner插件调用sonar。我还使用了重用报告标志。 如何从所有分析中排除所有测试类(Checkstyle、Findbugs、Coverage)

我目前正在使用以下插件配置:

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"
}
谢谢

试试这个:

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部分中使用excludes属性

    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=value应该与您的工作区相对,即src/java/com/../…)

sonarRunner插件已被弃用。请切换到官方SonarQube插件:

到目前为止您尝试过什么?您当前如何配置源集?显示您的插件配置。我的配置如下:sonarRunner{sonarProperties{property“sonar.host.url”、“property”sonar.scm.disabled、“true”property“sonar.login”、“property”sonar.password“、“property”sonar.sources、“src”property“sonar.Exclutions”、“*/test/***/.java”property“sonar.projectVersion”,project.releaseDisplayName//这些不应该改变任何东西,因为sonar使用gradle的默认设置//属性“sonar.tests”,“test”}你的源集设置如何?源集{main{java{srcDir'src'srcDir'src gen'}测试{java{srcDir'test}}你能试着注释掉这一行吗:property“sonar.sources”、“src”。插件应该选择main作为默认源集,并选择test作为默认测试源集
    def generatedSources = ['com/yahoo/**', 'com/amazon/**']

    test {
         jacoco {
              excludes = generatedSources
         }
    }

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