@@ -5,9 +5,6 @@ import com.android.build.api.artifact.MultipleArtifact
5
5
import com.android.build.api.dsl.BuildType
6
6
import com.android.build.api.variant.AndroidComponentsExtension
7
7
import com.android.build.api.variant.Variant
8
- import com.android.build.gradle.AppExtension
9
- import com.android.build.gradle.LibraryExtension
10
- import com.android.build.gradle.api.SourceKind
11
8
import org.gradle.api.GradleException
12
9
import org.gradle.api.NamedDomainObjectContainer
13
10
import org.gradle.api.Plugin
@@ -20,6 +17,7 @@ import org.neotech.plugin.rootcoverage.utilities.afterAndroidPluginApplied
20
17
import org.neotech.plugin.rootcoverage.utilities.assertMinimumRequiredAGPVersion
21
18
import org.neotech.plugin.rootcoverage.utilities.fileTree
22
19
import org.neotech.plugin.rootcoverage.utilities.onVariant
20
+ import org.neotech.plugin.rootcoverage.utilities.getReportOutputFile
23
21
import java.io.File
24
22
25
23
class RootCoveragePlugin : Plugin <Project > {
@@ -52,30 +50,9 @@ class RootCoveragePlugin : Plugin<Project> {
52
50
}
53
51
}
54
52
55
- private fun createSubProjectCoverageTask (subProject : Project ) {
56
- val task = subProject.tasks.create(" coverageReport" , JacocoReport ::class .java)
57
-
58
- // Make sure to only read from the rootProjectExtension after the project has been evaluated
59
- subProject.afterEvaluate {
60
- task.reports.html.required.set(rootProjectExtension.generateHtml)
61
- task.reports.xml.required.set(rootProjectExtension.generateXml)
62
- task.reports.csv.required.set(rootProjectExtension.generateCsv)
63
- }
64
-
65
- // Make sure to configure this JacocoReport task after the JaCoCoPlugin itself has been fully applied, otherwise the JaCoCoPlugin
66
- // may override settings in configureJacocoReportsDefaults()
67
- // https://github.com/gradle/gradle/blob/c177053ff95a1582c7919befe67993e0f1677f53/subprojects/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPlugin.java#L211
68
- subProject.pluginManager.withPlugin(" jacoco" ) {
69
- task.group = " reporting"
70
- task.description = " Generates a Jacoco for this Gradle module."
71
-
72
- task.reports.html.outputLocation.set(subProject.file(" ${subProject.buildDir} /reports/jacoco" ))
73
- task.reports.xml.outputLocation.set(subProject.file(" ${subProject.buildDir} /reports/jacoco.xml" ))
74
- task.reports.csv.outputLocation.set(subProject.file(" ${subProject.buildDir} /reports/jacoco.csv" ))
75
- }
76
-
77
- // subProject.assertAndroidCodeCoverageVariantExists()
78
53
54
+ private fun createSubProjectCoverageTask (subProject : Project ) {
55
+ val task = subProject.createJacocoReportTask(rootProjectExtension)
79
56
task.addSubProject(task.project)
80
57
}
81
58
@@ -95,9 +72,9 @@ class RootCoveragePlugin : Plugin<Project> {
95
72
project.pluginManager.withPlugin(" jacoco" ) {
96
73
task.group = " reporting"
97
74
task.description = " Generates a Jacoco report with combined results from all the subprojects."
98
- task.reports.html.outputLocation.set(project.file( " ${project.buildDir} /reports/ jacoco" ))
99
- task.reports.xml.outputLocation.set(project.file( " ${project.buildDir} /reports/ jacoco.xml" ))
100
- task.reports.csv.outputLocation.set(project.file( " ${project.buildDir} /reports/ jacoco.csv" ))
75
+ task.reports.html.outputLocation.set(project.getReportOutputFile( " jacoco" ))
76
+ task.reports.xml.outputLocation.set(project.getReportOutputFile( " jacoco.xml" ))
77
+ task.reports.csv.outputLocation.set(project.getReportOutputFile( " jacoco.csv" ))
101
78
}
102
79
103
80
project.allprojects.forEach { subProject ->
0 commit comments