diff --git a/README.md b/README.md index ab2af301..e98c7114 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Maven generated plugin documentation: |------------------|--------------------------------------------------------------------------------------------------| | `1.4.11` | [Plugin Info](http://scoverage.github.io/scoverage-maven-plugin/1.4.11/plugin-info.html) | -##### Prerequisities / limitations +##### Prerequisites / limitations Plugin is compatible with two Maven Scala compiler plugins: @@ -61,7 +61,7 @@ This can be set as project property. ```xml - 1.4.11 + 2.0.0 ``` @@ -69,12 +69,12 @@ This can be set as project property. ##### Scala version configuration -Plugin supports Scala 2.10.x, 2.11.x, 2.12.x and 2.13.x versions by automatically loading and configuring scalac-scoverage-plugin_2.10, scalac-scoverage-plugin_2.11, scalac-scoverage-plugin_2.12 or scalac-scoverage-plugin_2.13 Scalac SCoverage Plugin artifact. For this to work Scala version has to be set. It can be done by defining `scalaVersion` plugin configuration parameter or `scala.version` project property. Without this setting, coverage will not be calculated. +Plugin supports Scala 2.12.x and 2.13.x versions by automatically loading and configuring matching `scalac-scoverage-plugin` Scalac SCoverage Plugin artifact. For this to work Scala version has to be set. It can be done by defining `scalaVersion` plugin configuration parameter or `scala.version` project property. Without this setting, coverage will not be calculated. ```xml - 2.13.8 + 2.13.12 ``` @@ -90,7 +90,7 @@ or scoverage-maven-plugin ${scoverage.plugin.version} - 2.13.8 + 2.13.12 @@ -113,6 +113,8 @@ The first method is better because once the property is defined it's value can b ``` +For Scala 2.10 and 2.11 support please use Scoverage Maven plugin `1.4.11`. + ##### Scalac SCoverage plugin version configuration Maven SCoverage plugin uses by default the latest version of the [scalac-scoverage-plugin](https://github.com/scoverage/scalac-scoverage-plugin) available on its release day. @@ -122,7 +124,7 @@ It can be configured by defining `scalacPluginVersion` plugin configuration para ```xml - 1.4.11 + 2.0.11 ``` @@ -138,7 +140,7 @@ or scoverage-maven-plugin ${scoverage.plugin.version} - 1.4.11 + 2.0.11 diff --git a/pom.xml b/pom.xml index f14cf393..214fe15f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ under the License. 4.0.0 org.scoverage scoverage-maven-plugin - 1.4.12-SNAPSHOT + 2.0.0-SNAPSHOT maven-plugin SCoverage Maven Plugin diff --git a/src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java b/src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java index ca621eab..d78e86eb 100644 --- a/src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java +++ b/src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java @@ -134,7 +134,7 @@ public class SCoveragePreCompileMojo * * @since 1.0.0 */ - @Parameter( property = "scoverage.scalacPluginVersion", defaultValue = "" ) + @Parameter( property = "scoverage.scalacPluginVersion", defaultValue = "2.0.11" ) private String scalacPluginVersion; /** @@ -230,15 +230,7 @@ public void execute() throws MojoExecutionException String resolvedScalaVersion = resolveScalaVersion(); if ( resolvedScalaVersion != null ) { - if ( "2.10".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.10." ) ) - { - scalaBinaryVersion = "2.10"; - } - else if ( "2.11".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.11." ) ) - { - scalaBinaryVersion = "2.11"; - } - else if ( "2.12".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.12." ) ) + if ( "2.12".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.12." ) ) { scalaBinaryVersion = "2.12"; } @@ -426,79 +418,33 @@ private void setProperty( Properties projectProperties, String propertyName, Str } } + private ArtifactVersion getScalacPluginVersion() { + if ( scalacPluginVersion == null || scalacPluginVersion.isEmpty()) { + throw new IllegalStateException("scalacPluginVersion is unset."); + } else if ( scalacPluginVersion.startsWith("1.") ) { + throw new IllegalStateException( String.format( "Unsupported scalacPluginVersion \"%s\". Please use scalacPluginVersion 2.0.0+ or use older version of scoverage-maven-plugin", scalacPluginVersion ) ); + } else { + return new DefaultArtifactVersion(scalacPluginVersion); + } + } + private List getScalaScoveragePluginArtifacts(String resolvedScalaVersion, String scalaMainVersion ) throws ArtifactNotFoundException, ArtifactResolutionException { - String resolvedScalacPluginVersion = scalacPluginVersion; - if ( resolvedScalacPluginVersion == null || "".equals( resolvedScalacPluginVersion ) ) - { - for ( Artifact artifact : pluginArtifacts ) - { - if ( "org.scoverage".equals( artifact.getGroupId() ) - && artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) ) - { - resolvedScalacPluginVersion = artifact.getVersion(); - break; - } - } - } - - // There are 3 cases depending on the version of scalac-scoverage-plugin - // * Version 2.0.0 onwards - 3 artifacts, plugin using resolvedScalaVersion - // * Version 1.4.2 - 1 artifact, plugin using resolvedScalaVersion falling back to scalaMainVersion - // * Version 1.4.1 older - 1 artifact, plugin using scalaMainVersion - // - final ArtifactVersion pluginArtifactVersion = new DefaultArtifactVersion(resolvedScalacPluginVersion); - if(pluginArtifactVersion.getMajorVersion() >= 2) { - List resolvedArtifacts = new ArrayList<>(); - resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, resolvedScalacPluginVersion)); - resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-domain_" + scalaMainVersion, resolvedScalacPluginVersion)); - resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-serializer_" + scalaMainVersion, resolvedScalacPluginVersion)); - return resolvedArtifacts; - } else if (pluginArtifactVersion.getMajorVersion() == 1 && pluginArtifactVersion.getMinorVersion() == 4 && pluginArtifactVersion.getIncrementalVersion() == 2) - { - try - { - return Collections.singletonList( - getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, resolvedScalacPluginVersion ) - ); - } - catch ( ArtifactNotFoundException | ArtifactResolutionException e2 ) - { - getLog().warn( String.format( "Artifact \"org.scoverage:scalac-scoverage-plugin_%s:%s\" not found, " + - "falling back to \"org.scoverage:scalac-scoverage-plugin_%s:%s\"", - resolvedScalaVersion, resolvedScalacPluginVersion, scalaMainVersion, resolvedScalacPluginVersion ) ); - return Collections.singletonList( - getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion, resolvedScalacPluginVersion ) - ); - } - } else { - return Collections.singletonList( - getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion, resolvedScalacPluginVersion ) - ); - } + String resolvedScalacPluginVersion = getScalacPluginVersion().toString(); + List resolvedArtifacts = new ArrayList<>(); + resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, resolvedScalacPluginVersion)); + resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-domain_" + scalaMainVersion, resolvedScalacPluginVersion)); + resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-serializer_" + scalaMainVersion, resolvedScalacPluginVersion)); + return resolvedArtifacts; } private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion ) throws ArtifactNotFoundException, ArtifactResolutionException { - String resolvedScalacRuntimeVersion = scalacPluginVersion; - if ( resolvedScalacRuntimeVersion == null || "".equals( resolvedScalacRuntimeVersion ) ) - { - for ( Artifact artifact : pluginArtifacts ) - { - if ( "org.scoverage".equals( artifact.getGroupId() ) - && artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) ) - { - resolvedScalacRuntimeVersion = artifact.getVersion(); - break; - } - } - } - return getResolvedArtifact( "org.scoverage", "scalac-scoverage-runtime_" + scalaMainVersion, - resolvedScalacRuntimeVersion ); + getScalacPluginVersion().toString() ); } /**