Java 如何设置Scala代码覆盖率指标?

Java 如何设置Scala代码覆盖率指标?,java,scala,gradle,sonarqube,Java,Scala,Gradle,Sonarqube,我们正在尝试使用gradle在Sonarqube中获得Scala的代码覆盖率: classpath "gradle.plugin.org.scoverage:gradle-scoverage:3.1.5" classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1" 我们正在我们的build.gradle中实施: buildscript { repositorie

我们正在尝试使用gradle在Sonarqube中获得Scala的代码覆盖率:

classpath "gradle.plugin.org.scoverage:gradle-scoverage:3.1.5"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"
我们正在我们的build.gradle中实施:

buildscript {
    repositories {
        maven {
            url <maven_endpoint>
            allowInsecureProtocol true
        }
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.3.0.RELEASE'
        classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
        classpath "com.palantir.gradle.docker:gradle-docker:0.25.0"
        classpath "gradle.plugin.org.scoverage:gradle-scoverage:3.1.5"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"
    }
}

allprojects {
    apply plugin: 'idea'
    apply plugin: 'org.sonarqube'

    idea {
        module {
            downloadJavadoc = false
            downloadSources = true
        }
    }
}

def allTestCoverageFile = "${project.buildDir}/jacoco/test.exec"

sonarqube {
    properties {
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.sources", "${projectDir}/src/main/scala/"
        property "sonar.tests", "${projectDir}/src/test/scala/"
        property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/"
        property "sonar.scala.version", "$scala_2_12_version"
        property "sonar.scala.coverage.disable", "false"
        property "sonar.scala.scalastyle.disable", "false"
        property "sonar.scala.scoverage.reportPath", "${project.buildDir}/scala/scoverage-report/scoverage.xml"
        property "sonar.scala.scapegoat.reportPath", "${project.buildDir}/scala/scapegoat-report/scapegoat.xml"
        property "sonar.scala.scapegoat.disable", "false"
    }
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'scala'
    apply plugin: 'idea'
    apply plugin: 'maven-publish'
    apply plugin: 'org.sonarqube'
    apply plugin: 'jacoco'
    jacoco { toolVersion = "0.8.5" }

    sonarqube {
        properties {
            property "sonar.sources", "src"
            property "sonar.jacoco.reportPaths", allTestCoverageFile
        }
    }

    description = 'Notification Service'

    java {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
        withSourcesJar()
    }

    repositories {

        mavenLocal()

        maven {
            url <maven_endpoint>
            allowInsecureProtocol true
        }
        maven {
            url <maven_endpoint>
            allowInsecureProtocol true
        }
        maven {
            url <maven_endpoint>
            allowInsecureProtocol true
        }
    }

    dependencies {
        implementation "org.scala-lang:scala-library:$scala_2_12_version"

        testImplementation ("org.mockito:mockito-core") {version {strictly "2.15.0"}}
        testImplementation "org.scalatestplus:scalatestplus-junit_2.12:1.0.0-M2"
    }

    test {
        exclude '**/*ISpec.class'
        testLogging {
            showStandardStreams = true
            exceptionFormat = 'full'
            events 'started', 'passed', 'skipped', 'failed'
        }
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
            }
        }
        repositories {

            maven {
                name "applications"
                def releasesUrl = <releases endpoint>
                def snapshotsUrl = <snapshots endpoint>
                url = version.endsWith('SNAPSHOT') ? snapshotsUrl : releasesUrl
                allowInsecureProtocol true
                credentials {
                    username 
                    password 
                }
            }

        }
    }

    task combineReports(type:JacocoReport) {
        sourceDirectories.setFrom fileTree("${projectDir}/src/main/scala/")
        classDirectories.setFrom fileTree("${buildDir}/classes/scala/main/")
        executionData.setFrom "${buildDir}/jacoco/integrationTest.exec", "${buildDir}/jacoco/test.exec"
        additionalSourceDirs.setFrom files(sourceSets.main.allJava.srcDirs)
        reports {
            html.enabled true
            html.destination file("${buildDir}/combinedTestHtml")
            xml.enabled false
            csv.enabled false
            sourceSets sourceSets.main
        }
    }

    task integrationReport(type: JacocoReport) {
        sourceDirectories.setFrom fileTree("${projectDir}/src/main/scala/")
        classDirectories.setFrom fileTree("${buildDir}/classes/scala/main/")
        executionData.setFrom "${buildDir}/jacoco/integrationTest.exec"
        additionalSourceDirs.setFrom files(sourceSets.main.allJava.srcDirs)
        reports {
            html.enabled true
            html.destination file("${buildDir}/jacocoIntegrationTestHtml")
            xml.enabled false
            csv.enabled false
            sourceSets sourceSets.main
        }
        def unitTestExec = file "${buildDir}/jacoco/test.exec"
        if (unitTestExec.exists()) {
            finalizedBy combineReports
        }
    }

    task dependencyTree(type: DependencyReportTask)
}

task updateVersion {
    doLast {
        Properties props = new Properties()
        File propsFile = new File("gradle.properties")
        props.load(propsFile.newDataInputStream())
        props.setProperty("version", "$version")
        props.store(propsFile.newWriter(), null)
        props.load(propsFile.newDataInputStream())
        println "Version set to $version in gradle.properties"
    }
}
buildscript{
存储库{
马文{
网址
allowInsecureProtocol true
}
}
依赖关系{
classpath'org.springframework.boot:springboot gradle插件:2.3.0.RELEASE'
classpath“io.spring.gradle:依赖项管理插件:1.0.9.RELEASE”
类路径“com.palantir.gradle.docker:gradle docker:0.25.0”
classpath“gradle.plugin.org.scoverage:gradle scoverage:3.1.5”
classpath“org.sonarsource.scanner.gradle:sonarqube-gradle插件:2.7.1”
}
}
所有项目{
应用插件:“创意”
应用插件:“org.sonarqube”
意念{
模块{
downloadJavadoc=false
downloadSources=true
}
}
}
def allTestCoverageFile=“${project.buildDir}/jacoco/test.exec”
声纳库贝{
性质{
属性“sonar.sourceEncoding”,“UTF-8”
属性“sonar.sources”,“${projectDir}/src/main/scala/”
属性“sonar.tests”,“${projectDir}/src/test/scala/”
属性“sonar.jacoco.reportPath”,“${project.buildDir}/jacoco/”
属性“sonar.scala.version”,“$scala\u 2\u 12\u version”
属性“sonar.scala.coverage.disable”、“false”
属性“sonar.scala.scalastyle.disable”、“false”
属性“sonar.scala.scoverage.reportPath”,“${project.buildDir}/scala/scoverage report/scoverage.xml”
属性“sonar.scala.scapegoat.reportPath”,“${project.buildDir}/scala/scapegoat report/scapegoat.xml”
属性“sonar.scala.替罪羊.disable”、“false”
}
}
子项目{
应用插件:“java”
应用插件:“scala”
应用插件:“创意”
应用插件:“maven发布”
应用插件:“org.sonarqube”
应用插件:“jacoco”
jacoco{toolVersion=“0.8.5”}
声纳库贝{
性质{
属性“sonar.sources”、“src”
属性“sonar.jacoco.reportpath”,AllTestCoverage文件
}
}
description='通知服务'
爪哇{
sourceCompatibility=JavaVersion.VERSION\u 1\u 8
targetCompatibility=JavaVersion.VERSION\u 1\u 8
withSourcesJar()
}
存储库{
mavenLocal()
马文{
网址
allowInsecureProtocol true
}
马文{
网址
allowInsecureProtocol true
}
马文{
网址
allowInsecureProtocol true
}
}
依赖关系{
实现“org.scala lang:scala库:$scala_2_12_版本”
测试实现(“org.mockito:mockito核心”){version{严格地说是“2.15.0”}
测试实现“org.scalatestplus:scalatestplus-junit_2.12:1.0.0-M2”
}
试验{
排除“***ISpec.class”
测试记录{
showStandardStreams=true
例外格式='full'
事件“已启动”、“已通过”、“已跳过”、“失败”
}
}
出版{
出版物{
mavenJava(MavenPublication){
来自components.java
}
}
存储库{
马文{
名称“应用程序”
def releasesUrl=
def snapshotsUrl=
url=version.endsWith('SNAPSHOT')?snapshotsUrl:releasesUrl
allowInsecureProtocol true
证书{
用户名
密码
}
}
}
}
任务组合报表(类型:JacocoReport){
sourceDirectories.setFrom fileTree(“${projectDir}/src/main/scala/”)
classDirectories.setFrom fileTree(“${buildDir}/classes/scala/main/”)
executionData.setFrom“${buildDir}/jacoco/integrationTest.exec”,“${buildDir}/jacoco/test.exec”
additionalSourceDirs.setFrom文件(sourceset.main.allJava.srcDirs)
报告{
html.true
html.destination文件(“${buildDir}/combinedTestHtml”)
启用xml.false
csv.0启用错误
sourceSets sourceSets.main
}
}
任务集成报告(类型:JacocoReport){
sourceDirectories.setFrom fileTree(“${projectDir}/src/main/scala/”)
classDirectories.setFrom fileTree(“${buildDir}/classes/scala/main/”)
executionData.setFrom“${buildDir}/jacoco/integrationTest.exec”
additionalSourceDirs.setFrom文件(sourceset.main.allJava.srcDirs)
报告{
html.true
html.destination文件(“${buildDir}/jacoIntegrationTestHTML”)
启用xml.false
csv.0启用错误
sourceSets sourceSets.main
}
def unitTestExec=文件“${buildDir}/jacoco/test.exec”
如果(unitTestExec.exists()){
由组合报表完成
}
}
任务依赖树(类型:DependencyReportTask)
}
任务更新{
多拉斯特{
Properties props=新属性()
File propsFile=新文件(“gradle.properties”)
加载(propsFile.newDataInputStream())
props.setProperty(“版本”,“$version”)
props.store(propsFile.newWriter(),null)
加载(propsFile.newDataInputStream())
println“gradle.properties中的版本设置为$Version”
}
}
在使用gradle构建之后,它不仅在Sonarqube本身中显示了0%的代码覆盖率,而且在使用gradle构建之后也不会创建scapegoat.xml和scoverage.xml。要解决此问题,我需要更改什么