29
29
import org .apache .maven .artifact .resolver .ArtifactNotFoundException ;
30
30
import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
31
31
import org .apache .maven .artifact .resolver .ArtifactResolver ;
32
+ import org .apache .maven .model .Dependency ;
32
33
import org .apache .maven .plugin .AbstractMojo ;
33
34
import org .apache .maven .plugin .MojoExecutionException ;
34
35
import org .apache .maven .plugins .annotations .Component ;
@@ -199,26 +200,27 @@ public void execute() throws MojoExecutionException
199
200
long ts = System .currentTimeMillis ();
200
201
201
202
String scalaMainVersion = null ;
202
- if ( scalaVersion != null )
203
+ String resolvedScalaVersion = resolveScalaVersion ();
204
+ if ( resolvedScalaVersion != null )
203
205
{
204
- if ( scalaVersion .startsWith ( "2.10." ) )
206
+ if ( resolvedScalaVersion .startsWith ( "2.10." ) )
205
207
{
206
208
scalaMainVersion = "2.10" ;
207
209
}
208
- else if ( scalaVersion .startsWith ( "2.11." ) )
210
+ else if ( resolvedScalaVersion .startsWith ( "2.11." ) )
209
211
{
210
212
scalaMainVersion = "2.11" ;
211
213
}
212
214
else
213
215
{
214
- getLog ().warn ( String .format ( "Skipping SCoverage execution - unknown Scala version \" %s\" " ,
215
- scalaVersion ) );
216
+ getLog ().warn ( String .format ( "Skipping SCoverage execution - unsupported Scala version \" %s\" " ,
217
+ resolvedScalaVersion ) );
216
218
return ;
217
219
}
218
220
}
219
221
else
220
222
{
221
- getLog ().info ( "Skipping SCoverage execution - Scala version not set" );
223
+ getLog ().warn ( "Skipping SCoverage execution - Scala version not set" );
222
224
return ;
223
225
}
224
226
@@ -318,6 +320,9 @@ else if ( scalaVersion.startsWith( "2.11." ) )
318
320
319
321
// Private utility methods
320
322
323
+ private static final String SCALA_LIBRARY_GROUP_ID = "org.scala-lang" ;
324
+ private static final String SCALA_LIBRARY_ARTIFACT_ID = "scala-library" ;
325
+
321
326
private static final String DATA_DIR_OPTION = "-P:scoverage:dataDir:" ;
322
327
private static final String EXCLUDED_PACKAGES_OPTION = "-P:scoverage:excludedPackages:" ;
323
328
private static final String EXCLUDED_FILES_OPTION = "-P:scoverage:excludedFiles:" ;
@@ -332,6 +337,26 @@ private String quoteArgument( String arg )
332
337
return arg .indexOf ( SPACE ) >= 0 ? DOUBLE_QUOTE + arg + DOUBLE_QUOTE : arg ;
333
338
}
334
339
340
+ private String resolveScalaVersion ()
341
+ {
342
+ String result = scalaVersion ;
343
+ if ( result == null )
344
+ {
345
+ // check project direct dependencies (transitive dependencies cannot be checked in this Maven lifecycle phase)
346
+ List <Dependency > dependencies = project .getDependencies ();
347
+ for ( Dependency dependency : dependencies )
348
+ {
349
+ if ( SCALA_LIBRARY_GROUP_ID .equals ( dependency .getGroupId () )
350
+ && SCALA_LIBRARY_ARTIFACT_ID .equals ( dependency .getArtifactId () ) )
351
+ {
352
+ result = dependency .getVersion ();
353
+ break ;
354
+ }
355
+ }
356
+ }
357
+ return result ;
358
+ }
359
+
335
360
private void setProperty ( Properties projectProperties , String propertyName , String newValue )
336
361
{
337
362
if ( projectProperties .containsKey ( propertyName ) )
0 commit comments