-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
build.gradle
68 lines (60 loc) · 2.65 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
plugins {
id 'java'
id 'jacoco'
id "org.sonarqube" version "5.0.0.4638"
}
allprojects {
version = '1.0.2'
group = 'org.sonarqube.sample'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'org.sonarqube'
sonar {
properties {
property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
}
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
}
apply from: "$project.rootDir/sonar.gradle"
// See here for more info: https://docs.gradle.org/6.4-rc-1/samples/sample_jvm_multi_project_with_code_coverage.html
//
// task to gather code coverage from multiple subprojects
// NOTE: the `JacocoReport` tasks do *not* depend on the `test` task by default. Meaning you have to ensure
// that `test` (or other tasks generating code coverage) run before generating the report.
// You can achieve this by calling the `test` lifecycle task manually
// $ ./gradlew test codeCoverageReport
tasks.register("codeCoverageReport", JacocoReport) {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
subprojects { subproject ->
subproject.plugins.withType(JacocoPlugin).configureEach {
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask ->
//the jacoco extension may be disabled for some projects
if (testTask.extensions.getByType(JacocoTaskExtension).isEnabled()) {
sourceSets subproject.sourceSets.main
executionData(testTask)
} else {
logger.warn('Jacoco extension is disabled for test task \'{}\' in project \'{}\'. this test task will be excluded from jacoco report.',testTask.getName(),subproject.getName())
}
}
// To automatically run `test` every time `./gradlew codeCoverageReport` is called,
// you may want to set up a task dependency between them as shown below.
// Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which
// may have a negative effect on the configuration time of your build.
subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach {
rootProject.tasks.codeCoverageReport.dependsOn(it)
}
}
}
// enable the different report types (html, xml, csv)
reports {
xml.required = true
html.required = true
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}