Skip to content

Commit 7dfcf94

Browse files
committed
remove the double-compilation of main scala files
1 parent c2f643a commit 7dfcf94

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/main/groovy/org/scoverage/ScoverageExtension.groovy

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.gradle.api.tasks.SourceSet
1212
import org.gradle.api.tasks.testing.Test
1313
import org.gradle.util.GFileUtils
1414

15+
import java.util.concurrent.Callable
16+
1517
/**
1618
* Defines a new SourceSet for the code to be instrumented.
1719
* Defines a new Test Task which executes normal tests with the instrumented classes.
@@ -56,18 +58,37 @@ class ScoverageExtension {
5658
description = 'Scoverage dependencies'
5759
}
5860

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)
6173

62-
java.source(mainSourceSet.java)
63-
scala.source(mainSourceSet.scala)
74+
java.source(original.java)
75+
scala.source(original.scala)
6476

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
6779
}
6880

6981
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+
})
7192
}
7293

7394
project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) {
@@ -125,19 +146,10 @@ class ScoverageExtension {
125146
}
126147
scalaCompileOptions.additionalParameters = parameters
127148
}
128-
// exclude the scala libraries that are added to enable scala version detection
129-
classpath += pluginDependencies
130149
// the compile task creates a store of measured statements
131150
outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml'))
132151
}
133152

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-
141153
t.tasks[ScoveragePlugin.REPORT_NAME].configure {
142154
classpath = project.buildscript.configurations.classpath + configuration
143155
main = 'org.scoverage.ScoverageReport'

src/main/groovy/org/scoverage/ScoveragePlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ScoveragePlugin implements Plugin<Project> {
1010
static String REPORT_NAME = 'reportScoverage'
1111
static String CHECK_NAME = 'checkScoverage'
1212
static String COMPILE_NAME = 'compileScoverageScala'
13+
static String COMPILE_TEST_NAME = 'compileTestScoverageScala'
1314

1415
@Override
1516
void apply(Project t) {

0 commit comments

Comments
 (0)