@@ -12,6 +12,8 @@ import org.gradle.api.tasks.SourceSet
12
12
import org.gradle.api.tasks.testing.Test
13
13
import org.gradle.util.GFileUtils
14
14
15
+ import java.util.concurrent.Callable
16
+
15
17
/**
16
18
* Defines a new SourceSet for the code to be instrumented.
17
19
* Defines a new Test Task which executes normal tests with the instrumented classes.
@@ -56,18 +58,37 @@ class ScoverageExtension {
56
58
description = ' Scoverage dependencies'
57
59
}
58
60
59
- project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
60
- def mainSourceSet = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
61
+ def mainSourceSet = project. sourceSets. create(' scoverage' ) {
62
+ def original = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
63
+
64
+ java. source(original. java)
65
+ scala. source(original. scala)
66
+
67
+ compileClasspath + = original. compileClasspath + project. configurations. scoverage
68
+ runtimeClasspath = it. output + project. configurations. runtime
69
+ }
70
+
71
+ def testSourceSet = project. sourceSets. create(' testScoverage' ) {
72
+ def original = project. sourceSets. getByName(SourceSet . TEST_SOURCE_SET_NAME )
61
73
62
- java. source(mainSourceSet . java)
63
- scala. source(mainSourceSet . scala)
74
+ java. source(original . java)
75
+ scala. source(original . scala)
64
76
65
- compileClasspath + = mainSourceSet. compileClasspath
66
- runtimeClasspath + = mainSourceSet. runtimeClasspath
77
+ compileClasspath = mainSourceSet. output + project . configurations . testCompile
78
+ runtimeClasspath = it . output + mainSourceSet. output + project . configurations . scoverage + project . configurations . testRuntime
67
79
}
68
80
69
81
project. tasks. create(ScoveragePlugin . TEST_NAME , Test . class) {
70
- dependsOn(project. tasks[ScoveragePlugin . COMPILE_NAME ])
82
+ conventionMapping. map(" testClassesDir" , new Callable<Object > () {
83
+ public Object call () throws Exception {
84
+ return testSourceSet. output. classesDir;
85
+ }
86
+ })
87
+ conventionMapping. map(" classpath" , new Callable<Object > () {
88
+ public Object call () throws Exception {
89
+ return testSourceSet. runtimeClasspath;
90
+ }
91
+ })
71
92
}
72
93
73
94
project. tasks. create(ScoveragePlugin . REPORT_NAME , JavaExec . class) {
@@ -125,19 +146,10 @@ class ScoverageExtension {
125
146
}
126
147
scalaCompileOptions. additionalParameters = parameters
127
148
}
128
- // exclude the scala libraries that are added to enable scala version detection
129
- classpath + = pluginDependencies
130
149
// the compile task creates a store of measured statements
131
150
outputs. file(new File (extension. dataDir, ' scoverage.coverage.xml' ))
132
151
}
133
152
134
- t. tasks[ScoveragePlugin . TEST_NAME ]. configure {
135
- def existingClasspath = classpath
136
- classpath = t. files(t. sourceSets[ScoveragePlugin . CONFIGURATION_NAME ]. output. classesDir) +
137
- pluginDependencies +
138
- existingClasspath
139
- }
140
-
141
153
t. tasks[ScoveragePlugin . REPORT_NAME ]. configure {
142
154
classpath = project. buildscript. configurations. classpath + configuration
143
155
main = ' org.scoverage.ScoverageReport'
0 commit comments