@@ -10,6 +10,9 @@ import org.gradle.api.plugins.scala.ScalaPlugin
1010import org.gradle.api.tasks.JavaExec
1111import org.gradle.api.tasks.SourceSet
1212import org.gradle.api.tasks.testing.Test
13+ import org.gradle.util.GFileUtils
14+
15+ import java.util.concurrent.Callable
1316
1417/**
1518 * Defines a new SourceSet for the code to be instrumented.
@@ -55,18 +58,37 @@ class ScoverageExtension {
5558 description = ' Scoverage dependencies'
5659 }
5760
58- project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
59- 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 )
6073
61- java. source(mainSourceSet . java)
62- scala. source(mainSourceSet . scala)
74+ java. source(original . java)
75+ scala. source(original . scala)
6376
64- compileClasspath + = mainSourceSet. compileClasspath
65- runtimeClasspath + = mainSourceSet. runtimeClasspath
77+ compileClasspath = mainSourceSet. output + project . configurations . testCompile
78+ runtimeClasspath = it . output + mainSourceSet. output + project . configurations . scoverage + project . configurations . testRuntime
6679 }
6780
6881 project. tasks. create(ScoveragePlugin . TEST_NAME , Test . class) {
69- 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+ })
7092 }
7193
7294 project. tasks. create(ScoveragePlugin . REPORT_NAME , JavaExec . class) {
@@ -116,20 +138,21 @@ class ScoverageExtension {
116138 if (extension. highlighting) {
117139 parameters. add(' -Yrangepos' )
118140 }
119- scalaCompileOptions . additionalParameters = parameters . collect { escape(it) }
120- // exclude the scala libraries that are added to enable scala version detection
121- classpath + = pluginDependencies
122- }
123-
124- t . tasks[ ScoveragePlugin . TEST_NAME ] . configure {
125- def existingClasspath = classpath
126- classpath = t . files(t . sourceSets[ ScoveragePlugin . CONFIGURATION_NAME ] . output . classesDir) +
127- pluginDependencies +
128- existingClasspath
141+ if (scalaCompileOptions . useAnt) {
142+ scalaCompileOptions . additionalParameters = parameters . collect { escape(it) }
143+ } else {
144+ doFirst {
145+ GFileUtils . deleteDirectory(destinationDir)
146+ }
147+ scalaCompileOptions . additionalParameters = parameters
148+ }
149+ // the compile task creates a store of measured statements
150+ outputs . file( new File (extension . dataDir, ' scoverage.coverage.xml ' ))
129151 }
130152
131153 t. tasks[ScoveragePlugin . REPORT_NAME ]. configure {
132- classpath = project. buildscript. configurations. classpath + configuration
154+ def classLocation = ScoverageExtension . class. getProtectionDomain(). getCodeSource(). getLocation()
155+ classpath = project. files(classLocation. file) + configuration
133156 main = ' org.scoverage.ScoverageReport'
134157 args = [
135158 extension. sources,
0 commit comments