1
1
import org.gradle.api.publish.maven.MavenPublication
2
2
import org.gradle.api.tasks.bundling.Jar
3
+ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
4
+ import org.gradle.api.tasks.testing.logging.TestLogEvent
3
5
import org.gradle.api.tasks.wrapper.Wrapper
4
- import org.junit.platform.console.options.Details
5
6
6
7
buildscript {
7
8
repositories {
@@ -14,10 +15,10 @@ buildscript {
14
15
dependencies {
15
16
classpath(" org.jetbrains.kotlin:kotlin-gradle-plugin:${property(" kotlin.version" )} " )
16
17
classpath(" com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" )
17
- classpath(" org.junit.platform:junit-platform-gradle-plugin:1.1.0-M1" )
18
18
}
19
19
}
20
20
plugins {
21
+ `lifecycle- base`
21
22
jacoco
22
23
}
23
24
apply {
@@ -35,15 +36,14 @@ allprojects {
35
36
}
36
37
}
37
38
38
- val jacocoTestResultTaskName = " jacocoJunit5TestReport "
39
+ val jacocoTestResultTaskName = " jacocoTestReport "
39
40
40
41
subprojects {
41
42
apply {
42
43
plugin(" com.jfrog.bintray" )
43
44
plugin(" kotlin" )
44
45
plugin(" maven-publish" )
45
46
plugin(" java-library" )
46
- plugin(" org.junit.platform.gradle.plugin" )
47
47
plugin(" jacoco" )
48
48
}
49
49
@@ -70,36 +70,39 @@ subprojects {
70
70
" testCompile" (junitJupiter(" junit-jupiter-api" ))
71
71
" testCompile" (junitJupiter(" junit-jupiter-params" ))
72
72
" testRuntime" (junitJupiter(" junit-jupiter-engine" ))
73
- " testRuntime" (create(group = " org.junit.platform" , name = " junit-platform-launcher" , version = " 1.1.0-M1 " ))
73
+ " testRuntime" (create(group = " org.junit.platform" , name = " junit-platform-launcher" , version = " 1.3.1 " ))
74
74
}
75
75
76
- junitPlatform {
77
- details = Details .VERBOSE
76
+ tasks.withType<Test >().configureEach {
77
+ extensions.configure(typeOf<JacocoTaskExtension >()) {
78
+ /*
79
+ * Fix for Jacoco breaking Build Cache support.
80
+ * https://github.com/gradle/gradle/issues/5269
81
+ */
82
+ isAppend = false
83
+ }
78
84
79
- filters {
80
- includeClassNamePatterns(" .*Test" , " .*Tests" , " .*Spec" )
85
+ useJUnitPlatform {
86
+ filter {
87
+ includeTestsMatching(" *Test" )
88
+ includeTestsMatching(" *Tests" )
89
+ includeTestsMatching(" *Spec" )
90
+ }
81
91
}
82
- }
83
92
84
- // Below, configure jacoco code coverage on all Junit 5 tests.
85
- val junitPlatformTest: JavaExec by tasks
93
+ testLogging {
94
+ events(TestLogEvent .FAILED , TestLogEvent .PASSED , TestLogEvent .SKIPPED , TestLogEvent .STARTED )
95
+ displayGranularity = 0
96
+ showExceptions = true
97
+ showCauses = true
98
+ showStackTraces = true
99
+ exceptionFormat = TestExceptionFormat .FULL
100
+ }
86
101
87
- jacoco {
88
- applyTo(junitPlatformTest)
102
+ reports.junitXml.destination = file(" ${rootProject.buildDir} /test-results/${project.name} " )
89
103
}
90
104
91
- val sourceSets = java.sourceSets
92
-
93
- task<JacocoReport >(jacocoTestResultTaskName) {
94
- group = LifecycleBasePlugin .VERIFICATION_GROUP
95
- description = " Generates code coverage report for the ${junitPlatformTest.name} task."
96
-
97
- executionData(junitPlatformTest)
98
- dependsOn(junitPlatformTest)
99
-
100
- sourceSets(sourceSets[" main" ])
101
- sourceDirectories = files(sourceSets[" main" ].allSource.srcDirs)
102
- classDirectories = files(sourceSets[" main" ].output)
105
+ tasks.withType<JacocoReport >().configureEach {
103
106
reports {
104
107
html.isEnabled = true
105
108
xml.isEnabled = true
@@ -125,12 +128,20 @@ subprojects {
125
128
}
126
129
}
127
130
128
- val jacocoRootReport = task< JacocoReport > (" jacocoRootReport" ) {
131
+ val jacocoRootReport = tasks.register (" jacocoRootReport" , JacocoReport :: class .java ) {
129
132
group = LifecycleBasePlugin .VERIFICATION_GROUP
130
133
description = " Generates code coverage report for all sub-projects."
131
134
132
135
val jacocoReportTasks =
133
- subprojects.map { it.tasks[jacocoTestResultTaskName] as JacocoReport }
136
+ subprojects
137
+ .asSequence()
138
+ .filter {
139
+ // Filter out source sets that don't have tests in them
140
+ // Otherwise, Jacoco tries to generate coverage data for tests that don't exist
141
+ ! it.java.sourceSets[" test" ].allSource.isEmpty
142
+ }
143
+ .map { it.tasks[jacocoTestResultTaskName] as JacocoReport }
144
+ .toList()
134
145
dependsOn(jacocoReportTasks)
135
146
136
147
val allExecutionData = jacocoReportTasks.map { it.executionData }
@@ -143,9 +154,10 @@ val jacocoRootReport = task<JacocoReport>("jacocoRootReport") {
143
154
144
155
subprojects.forEach { testedProject ->
145
156
val sourceSets = testedProject.java.sourceSets
146
- this @task.additionalSourceDirs = this @task.additionalSourceDirs?.plus(files(sourceSets[" main" ].allSource.srcDirs))
147
- this @task.sourceDirectories + = files(sourceSets[" main" ].allSource.srcDirs)
148
- this @task.classDirectories + = files(sourceSets[" main" ].output)
157
+ this @register.additionalSourceDirs =
158
+ this @register.additionalSourceDirs?.plus(files(sourceSets[" main" ].allSource.srcDirs))
159
+ this @register.sourceDirectories + = files(sourceSets[" main" ].allSource.srcDirs)
160
+ this @register.classDirectories + = files(sourceSets[" main" ].output)
149
161
}
150
162
151
163
reports {
@@ -160,27 +172,25 @@ allprojects {
160
172
pluginManager.withPlugin(" jacoco" ) {
161
173
// If this project has the plugin applied, configure the tool version.
162
174
jacoco {
163
- toolVersion = " 0.8.1 "
175
+ toolVersion = " 0.8.2 "
164
176
}
165
177
}
166
178
}
167
179
168
180
configurations.create(PUBLISHED_CONFIGURATION_NAME )
169
181
182
+ tasks.named(LifecycleBasePlugin .CHECK_TASK_NAME ).configure {
183
+ dependsOn(jacocoRootReport)
184
+ }
185
+
170
186
tasks.withType<Wrapper >().configureEach {
171
187
description = " Configure the version of gradle to download and use"
172
188
gradleVersion = " 4.10.2"
173
189
distributionType = Wrapper .DistributionType .ALL
174
190
}
175
191
176
192
fun DependencyHandler.junitJupiter (name : String ) =
177
- create(group = " org.junit.jupiter" , name = name, version = " 5.1.0-M1" )
178
-
179
- /* *
180
- * Configures the [junitPlatform][org.junit.platform.gradle.plugin.JUnitPlatformExtension] project extension.
181
- */
182
- fun Project .`junitPlatform` (configure : org.junit.platform.gradle.plugin.JUnitPlatformExtension .() -> Unit ) =
183
- extensions.configure(" junitPlatform" , configure)
193
+ create(group = " org.junit.jupiter" , name = name, version = " 5.3.1" )
184
194
185
195
/* *
186
196
* Retrieves or configures the [bintray][com.jfrog.bintray.gradle.BintrayExtension] project extension.
0 commit comments