Skip to content

Commit 57a036a

Browse files
committed
#140 Resolve scalac plugin file at execution time instead of configuration time
1 parent e5dd110 commit 57a036a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class ScoveragePlugin implements Plugin<PluginAware> {
2727

2828
static final String DEFAULT_REPORT_DIR = 'reports' + File.separatorChar + 'scoverage'
2929

30-
private volatile File pluginFile = null
3130
private final ConcurrentHashMap<Task, Set<? extends Task>> taskDependencies = new ConcurrentHashMap<>();
3231

3332
@Override
@@ -172,13 +171,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
172171
}
173172

174173
compileTask.configure {
175-
if (pluginFile == null) {
176-
pluginFile = project.configurations[CONFIGURATION_NAME].find {
177-
it.name.startsWith("scalac-scoverage-plugin")
178-
}
179-
}
180-
181-
List<String> parameters = ['-Xplugin:' + pluginFile.absolutePath]
174+
List<String> parameters = []
182175
List<String> existingParameters = scalaCompileOptions.additionalParameters
183176
if (existingParameters) {
184177
parameters.addAll(existingParameters)
@@ -198,6 +191,18 @@ class ScoveragePlugin implements Plugin<PluginAware> {
198191
scalaCompileOptions.additionalParameters = parameters
199192
// the compile task creates a store of measured statements
200193
outputs.file(new File(extension.dataDir.get(), 'scoverage.coverage.xml'))
194+
195+
dependsOn project.configurations[CONFIGURATION_NAME]
196+
doFirst {
197+
/*
198+
It is crucial that this would run in `doFirst`, as this resolves the (dependencies of the)
199+
configuration, which we do not want to do at configuration time (but only at execution time).
200+
*/
201+
def pluginFile = project.configurations[CONFIGURATION_NAME].find {
202+
it.name.startsWith("scalac-scoverage-plugin")
203+
}
204+
scalaCompileOptions.additionalParameters.add('-Xplugin:' + pluginFile.absolutePath)
205+
}
201206
}
202207

203208
project.gradle.taskGraph.whenReady { graph ->

0 commit comments

Comments
 (0)