|
1 | 1 | apply plugin: 'jacoco' |
2 | 2 |
|
| 3 | +def javaProjects = subprojects.findAll { p -> |
| 4 | + p.plugins.hasPlugin('java') || p.plugins.hasPlugin('java-library') |
| 5 | +} |
| 6 | + |
3 | 7 | tasks.register('jacocoRootTestReport', JacocoReport) { |
4 | | - dependsOn = subprojects.test |
5 | | - getSourceDirectories().from(subprojects.sourceSets.main.allSource.srcDirs) |
6 | | - getAdditionalSourceDirs().from(subprojects.sourceSets.main.allSource.srcDirs) |
7 | | - getClassDirectories().from(subprojects.sourceSets.main.output) |
8 | | - getExecutionData().from(subprojects.jacocoTestReport.executionData) |
| 8 | + // run tests + create per-project jacoco reports first |
| 9 | + dependsOn(javaProjects.collect { it.tasks.named('test') }) |
| 10 | + dependsOn(javaProjects.collect { it.tasks.named('jacocoTestReport') }) |
| 11 | + |
| 12 | + def mainSrcDirs = files(javaProjects.collect { it.sourceSets.main.allSource.srcDirs }) |
| 13 | + sourceDirectories.setFrom(mainSrcDirs) |
| 14 | + additionalSourceDirs.setFrom(mainSrcDirs) |
| 15 | + |
| 16 | + // execution data from subprojects |
| 17 | + executionData.setFrom(files(javaProjects.collect { |
| 18 | + it.tasks.named('jacocoTestReport').get().executionData |
| 19 | + })) |
| 20 | + |
| 21 | + // classes with excludes (no afterEvaluate needed) |
| 22 | + def allMainOutputs = files(javaProjects.collect { it.sourceSets.main.output }) |
| 23 | + classDirectories.setFrom(allMainOutputs.asFileTree.matching { |
| 24 | + exclude( |
| 25 | + 'org/web3j/abi/datatypes/generated/**', |
| 26 | + 'org/web3j/tuples/generated/**', |
| 27 | + 'org/web3j/ens/contracts/generated/**', |
| 28 | + 'org/gradle/**' |
| 29 | + ) |
| 30 | + }) |
| 31 | + |
9 | 32 | reports { |
10 | 33 | xml.required.set(true) |
11 | 34 | } |
12 | 35 |
|
13 | 36 | doFirst { |
14 | | - getExecutionData().from(executionData.findAll { it.exists() }) |
15 | | - } |
16 | | - |
17 | | - afterEvaluate { |
18 | | - getClassDirectories().from(files(classDirectories.files.collect { |
19 | | - fileTree(dir: it, |
20 | | - exclude: [ |
21 | | - 'org/web3j/abi/datatypes/generated/**', |
22 | | - 'org/web3j/tuples/generated/**', |
23 | | - 'org/web3j/ens/contracts/generated/**', |
24 | | - 'org/gradle/**' |
25 | | - ]) |
26 | | - })) |
| 37 | + executionData.setFrom(executionData.filter { it.exists() }) |
27 | 38 | } |
28 | 39 | } |
29 | 40 |
|
30 | 41 | jacoco { |
31 | 42 | toolVersion = "0.8.10" |
32 | 43 | } |
33 | | - |
|
0 commit comments