@@ -26,12 +26,15 @@ buildscript {
26
26
// For Apache Rat plugin to ignore non-Git files
27
27
classpath " org.ajoberstar:grgit:1.5.0"
28
28
classpath ' com.github.ben-manes:gradle-versions-plugin:0.12.0'
29
+ classpath ' org.scoverage:gradle-scoverage:2.0.1'
29
30
}
30
31
}
31
32
32
33
allprojects {
33
34
apply plugin : ' idea'
34
35
apply plugin : ' eclipse'
36
+ apply plugin : " jacoco"
37
+
35
38
repositories {
36
39
mavenCentral()
37
40
}
@@ -249,8 +252,50 @@ subprojects {
249
252
configProperties = [importControlFile : " $rootDir /checkstyle/import-control.xml" ]
250
253
}
251
254
test. dependsOn(' checkstyleMain' , ' checkstyleTest' )
255
+
256
+ // Ignore core since its a scala project
257
+ if (it. path != ' :core' ) {
258
+ // NOTE: Gradles Jacoco plugin does not support "offline instrumentation" this means that classes mocked by PowerMock
259
+ // may report 0 coverage, since the source was modified after initial instrumentation.
260
+ // See https://github.com/jacoco/jacoco/issues/51
261
+ jacocoTestReport {
262
+ dependsOn tasks. test
263
+ sourceSets sourceSets. main
264
+ reports {
265
+ html. enabled = true
266
+ xml. enabled = true
267
+ csv. enabled = false
268
+ }
269
+ }
270
+ }
271
+ }
272
+
273
+ // Aggregates all jacoco results into the root project directory
274
+ task jacocoRootReport (type : org.gradle.testing.jacoco.tasks.JacocoReport ) {
275
+ def javaProjects = subprojects. findAll { it. path != ' :core' }
276
+
277
+ description = ' Generates an aggregate report from all subprojects'
278
+ dependsOn(javaProjects. test)
279
+
280
+ additionalSourceDirs = files(javaProjects. sourceSets. main. allSource. srcDirs)
281
+ sourceDirectories = files(javaProjects. sourceSets. main. allSource. srcDirs)
282
+ classDirectories = files(javaProjects. sourceSets. main. output)
283
+ executionData = files(javaProjects. jacocoTestReport. executionData)
284
+
285
+ reports {
286
+ html. enabled = true
287
+ xml. enabled = true
288
+ }
289
+
290
+ // workaround to ignore projects that don't have any tests at all
291
+ onlyIf = { true }
292
+ doFirst {
293
+ executionData = files(executionData. findAll { it. exists() })
294
+ }
252
295
}
253
296
297
+ task reportCoverage (dependsOn : [' jacocoRootReport' , ' core:reportScoverage' ])
298
+
254
299
for ( sv in [' 2_10' , ' 2_11' ] ) {
255
300
String svInDot = sv. replaceAll( " _" , " ." )
256
301
@@ -320,6 +365,7 @@ project(':core') {
320
365
println " Building project 'core' with Scala version ${ versions.scala} "
321
366
322
367
apply plugin : ' scala'
368
+ apply plugin : " org.scoverage"
323
369
archivesBaseName = " kafka_${ versions.baseScala} "
324
370
325
371
dependencies {
@@ -351,7 +397,20 @@ project(':core') {
351
397
testCompile libs. apachedsJdbmPartition
352
398
testCompile libs. junit
353
399
testCompile libs. scalaTest
400
+
401
+ scoverage libs. scoveragePlugin
402
+ scoverage libs. scoverageRuntime
403
+ }
404
+
405
+ jacocoTestReport. enabled = false
406
+ scoverage {
407
+ reportDir = file(" ${ rootProject.buildDir} /scoverage" )
408
+ highlighting = false
409
+ }
410
+ checkScoverage {
411
+ minimumRate = 0.0
354
412
}
413
+ checkScoverage. shouldRunAfter(' test' )
355
414
356
415
configurations {
357
416
// manually excludes some unnecessary dependencies
0 commit comments