@@ -63,27 +63,8 @@ class ScoveragePlugin implements Plugin<PluginAware> {
63
63
}
64
64
65
65
project. afterEvaluate {
66
+ def scalaVersion = resolveScalaVersion(project)
66
67
def scoverageVersion = project. extensions. scoverage. scoverageVersion. get()
67
- def scalaVersion = null
68
-
69
- def scalaLibrary = project. configurations. compile. dependencies. find {
70
- it. group == " org.scala-lang" && it. name == " scala-library"
71
- }
72
-
73
- if (scalaLibrary != null ) {
74
- scalaVersion = scalaLibrary. version
75
- }
76
-
77
- if (scalaVersion == null && project. pluginManager. hasPlugin(" io.spring.dependency-management" )) {
78
- scalaVersion = project. dependencyManagement. compile. managedVersions[" org.scala-lang:scala-library" ]
79
- }
80
-
81
- if (scalaVersion == null ) {
82
- scalaVersion = project. extensions. scoverage. scoverageScalaVersion. get()
83
- } else {
84
- scalaVersion = scalaVersion. substring(0 , scalaVersion. lastIndexOf(" ." ))
85
- }
86
-
87
68
def fullScoverageVersion = " $scalaVersion :$scoverageVersion "
88
69
89
70
project. logger. info(" Using scoverage scalac plugin version '$fullScoverageVersion '" )
@@ -319,6 +300,24 @@ class ScoveragePlugin implements Plugin<PluginAware> {
319
300
}
320
301
}
321
302
303
+ private String resolveScalaVersion (Project project ) {
304
+
305
+ def resolvedDependencies = project. configurations. compileClasspath. resolvedConfiguration. firstLevelModuleDependencies
306
+
307
+ def scalaLibrary = resolvedDependencies. find {
308
+ it. moduleGroup == " org.scala-lang" && it. moduleName == " scala-library"
309
+ }
310
+
311
+ if (scalaLibrary == null ) {
312
+ project. logger. info(" No scala library detected. Using property 'scoverageScalaVersion'" )
313
+ return project. extensions. scoverage. scoverageScalaVersion. get()
314
+ } else {
315
+ project. logger. info(" Detected scala library in compilation classpath" )
316
+ def fullScalaVersion = scalaLibrary. moduleVersion
317
+ return fullScalaVersion. substring(0 , fullScalaVersion. lastIndexOf(" ." ))
318
+ }
319
+ }
320
+
322
321
private Set<? extends Task > recursiveDependenciesOf (Task task ) {
323
322
if (! taskDependencies. containsKey(task)) {
324
323
def directDependencies = task. getTaskDependencies(). getDependencies(task)
0 commit comments