Skip to content

Commit 1694dc1

Browse files
authored
Merge pull request #13 from ie3-institute/ck/#12-coverage4scala
Adding scoverage to report Scala test coverage
2 parents 41cecdc + bebbc1b commit 1694dc1

8 files changed

+30
-145
lines changed

Jenkinsfile

+7-11
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void setJavaVersion(javaVersionId) {
4545
String featureBranchName = ""
4646

4747
//// gradle tasks that are executed
48-
def gradleTasks = "--refresh-dependencies clean spotlessCheck pmdMain pmdTest spotbugsMain spotbugsTest allTests" // the gradle tasks that are executed on ALL projects
49-
def mainProjectGradleTasks = "jacocoTestReport jacocoTestCoverageVerification" // additional tasks that are only executed on project 0 (== main project)
48+
def gradleTasks = "--refresh-dependencies clean spotlessCheck pmdMain pmdTest check" // the gradle tasks that are executed on ALL projects
49+
def mainProjectGradleTasks = "reportScoverage checkScoverage" // additional tasks that are only executed on project 0 (== main project)
5050
// if you need additional tasks for deployment add them here
5151
// NOTE: artifactory task with credentials will be added below
5252
def deployGradleTasks = ""
@@ -99,7 +99,7 @@ if (env.BRANCH_NAME == "master") {
9999

100100

101101
// test the project
102-
stage("gradle allTests ${projects.get(0)}") {
102+
stage("gradle check ${projects.get(0)}") {
103103
// build and test the project
104104
gradle("${gradleTasks} ${mainProjectGradleTasks}")
105105
}
@@ -210,7 +210,7 @@ if (env.BRANCH_NAME == "master") {
210210
}
211211

212212
// test the project
213-
stage("gradle allTests ${projects.get(0)}") {
213+
stage("gradle check ${projects.get(0)}") {
214214

215215
// build and test the project
216216
gradle("${gradleTasks} ${mainProjectGradleTasks}")
@@ -326,15 +326,11 @@ def publishReports() {
326326
// publish test reports
327327
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/tests/allTests', reportFiles: 'index.html', reportName: "${projects.get(0)}_java_tests_report", reportTitles: ''])
328328

329-
// publish jacoco report for main project only
330-
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/jacoco', reportFiles: 'index.html', reportName: "${projects.get(0)}_jacoco_report", reportTitles: ''])
331-
329+
// publish scoverage reports
330+
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/scoverage', reportFiles: 'scoverage.xml', reportName: "${projects.get(0)}_scoverage_report", reportTitles: ''])
331+
332332
// publish pmd report for main project only
333333
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/pmd', reportFiles: 'main.html', reportName: "${projects.get(0)}_pmd_report", reportTitles: ''])
334-
335-
// publish spotbugs report for main project only
336-
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/spotbugs', reportFiles: 'main.html', reportName: "${projects.get(0)}_spotbugs_report", reportTitles: ''])
337-
338334
}
339335

340336

build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ plugins {
55
id 'scala' // scala support
66
id 'maven-publish' // publish to a maven repo (local or mvn central, has to be defined)
77
id 'pmd' // code check, working on source code
8-
id 'com.github.spotbugs' version '2.0.0' // code check, working on byte code
98
id 'com.diffplug.gradle.spotless' version '3.28.1'// code format
109
id "de.undercouch.download" version "3.4.3" // downloads plugin
1110
id 'jacoco' // java code coverage plugin
1211
id "org.sonarqube" version "2.8" // sonarqube
12+
id 'org.scoverage' version '4.0.2' // Code coverage plugin for scala
13+
id "com.github.maiflai.scalatest" version "0.26" // run scalatest without specific task
1314
}
1415

1516
ext {
@@ -28,13 +29,11 @@ group = 'com.github.ie3-institute'
2829
description = 'simbench4ie3'
2930
version = '1.0-SNAPSHOT'
3031

31-
apply from: scriptsLocation + 'tests.gradle'
3232
apply from: scriptsLocation + 'pmd.gradle'
33-
apply from: scriptsLocation + 'spotbugs.gradle'
3433
apply from: scriptsLocation + 'spotless.gradle'
3534
apply from: scriptsLocation + 'checkJavaVersion.gradle'
3635
apply from: scriptsLocation + 'tscfg.gradle' // config tasks
37-
apply from: scriptsLocation + 'jacoco.gradle' // jacoco java code coverage
36+
apply from: scriptsLocation + 'scoverage.gradle'
3837

3938
repositories {
4039
jcenter() //searches in bintray's repository 'jCenter', which contains Maven Central
@@ -79,6 +78,8 @@ dependencies {
7978
testCompile "org.scalatest:scalatest_${scalaVersion}:3.0.8"
8079
testRuntime "org.pegdown:pegdown:1.6.0" // HTML report for scalatest
8180
compile 'org.mockito:mockito-core:+' // mocking framework
81+
scoverage "org.scoverage:scalac-scoverage-plugin_${scalaVersion}:1.4.1"
82+
scoverage "org.scoverage:scalac-scoverage-runtime_${scalaVersion}:1.4.1"
8283

8384
// config //
8485
implementation 'com.typesafe:config:+'

gradle/scripts/jacoco.gradle

-71
This file was deleted.

gradle/scripts/scoverage.gradle

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Scala code coverage gradle plugin see https://github.com/scoverage/gradle-scoverage#configuration and
3+
* https://github.com/scoverage/gradle-scoverage/issues/109 for details
4+
*/
5+
scoverage {
6+
scoverageVersion = '1.4.1'
7+
scoverageScalaVersion = '2.13.1'
8+
coverageOutputHTML = false
9+
coverageOutputXML = true
10+
coverageOutputCobertura = false
11+
minimumRate = 0.6 // minimum code coverage
12+
coverageDebug = false
13+
}

gradle/scripts/sonarqube.gradle

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
sonarqube {
22
properties {
3-
// todo CK enable accordingly!
43
// general stuff
54
property 'sonar.projectName', 'simbench4ie3' // project name
65
property 'sonar.verbose', 'true' // verbose mode
@@ -25,12 +24,8 @@ sonarqube {
2524
"build/reports/spotbugs/main.xml",
2625
"build/reports/spotbugs/test.xml"] // Comma-delimited list of paths to reports from SpotBugs
2726
// scala specific stuff
28-
//property 'sonar.scala.coverage.reportPaths', ''//todo enable when scoverage gradle plugin is available for scala 2.13
27+
property 'sonar.scala.coverage.reportPaths', 'build/reports/scoverage/scoverage.xml'
2928

30-
// groovy specific stuff
31-
property 'sonar.groovy.jacoco.reportPath', 'build/jacoco/test.exec' // unit tests reports dir
32-
/// integration tests reports dir (if any)
33-
property 'sonar.groovy.jacoco.itReportPath', 'build/jacoco/allTests.exec'
3429
property 'sonar.groovy.binaries', 'build/classes/groovy' // groovy binaries
3530

3631
// remove auto generated SimonaConfig file from analysis
@@ -43,7 +38,7 @@ project.tasks["sonarqube"].dependsOn "pmdMain"
4338
project.tasks["sonarqube"].dependsOn "pmdTest"
4439
project.tasks["sonarqube"].dependsOn "spotbugsMain"
4540
project.tasks["sonarqube"].dependsOn "spotbugsTest"
46-
project.tasks["sonarqube"].dependsOn "allTests"
41+
project.tasks["sonarqube"].dependsOn "check"
4742

48-
project.tasks["sonarqube"].dependsOn "jacocoTestReport"
49-
project.tasks["sonarqube"].dependsOn "jacocoTestCoverageVerification"
43+
project.tasks["sonarqube"].dependsOn "reportScoverage"
44+
project.tasks["sonarqube"].dependsOn "checkScoverage"

gradle/scripts/spotbugs.gradle

-21
This file was deleted.

gradle/scripts/spotless.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spotless {
3737

3838
// removes unnecessary whitespace, indents with tabs and ends on new line for gradle, md and gitignore files and config-XMLs
3939
format 'misc', {
40-
target '**/*.gradle', '**/*.md', '**/.gitignore', 'configs/**'
40+
target '**/*.md', '**/.gitignore', 'configs/**'
4141
trimTrailingWhitespace()
4242
indentWithTabs()
4343
endWithNewline()

gradle/scripts/tests.gradle

-28
This file was deleted.

0 commit comments

Comments
 (0)