我们正在尝试使用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"
}
}
在使用gradle构建之后,它不仅在sonarqube本身中显示了0%的代码覆盖率,而且之后也没有创建scapegoat.xml和scoverage.xml。我需要更改什么来解决此问题?
暂无答案!
目前还没有任何答案,快来回答吧!