scalascala-3scoveragemill

Using scoverage with scala3 and mill


TL;DR -- How do I configure the mill-contrib-scoverage plugin to work with Scala3?

Details:

Using the instructions at the Mill contributor's page, I get the following error when running the scoverage.htmlReport task (note the "Scoverage 1.x does not support Scala 3"):

bwbecker@beta oat-degreeAudit3 % mill _solver.jvm.scoverage.htmlReport
[7/14] _solver.jvm.scoverageToolsClasspath 
Detected an unsupported Scala version (2.13.12). Using Scala version 2.13.8 to resolve scoverage 1.4.0 reporting API.
[7/14] _solver.jvm.scoverageToolsClasspath | Downloading [2/2] artifacts (~0/0 bytes)
1 targets failed
_solver.jvm.scoverageToolsClasspath Scoverage 1.x does not support Scala 3. You have to update to at least Scala 3.2 and Scoverage 2.0, 
Resolution failed for 1 modules:
--------------------------------------------
  org.scoverage:scalac-scoverage-plugin_2.13.8:1.4.0 
    not found: /Users/bwbecker/.ivy2/local/org.scoverage/scalac-scoverage-plugin_2.13.8/1.4.0/ivys/ivy.xml
    not found: https://repo1.maven.org/maven2/org/scoverage/scalac-scoverage-plugin_2.13.8/1.4.0/scalac-scoverage-plugin_2.13.8-1.4.0.pom

I note that the most recent version of scoverage is 2.1.1, not 1.4.0 as in the Mill documentation. Changing it doesn't help.

I believe the issue is the import statement:

import $ivy.`com.lihaoyi::mill-contrib-scoverage:`

I don't know how to specify 2.1.1 here -- or even if the most recent version of the Mill module is compatible with 2.1.1.

Per instructions regarding Mill plugins in general, I tried

import $ivy.`com.lihaoyi::mill-contrib-scoverage$MILL_BIN_PLATFORM:2.1.1`

but got the error

Resolution failed for 1 modules:
--------------------------------------------
  com.lihaoyi:mill-contrib-scoverage0.11_2.13:2.1.1 
    not found: /Users/bwbecker/.ivy2/local/com.lihaoyi/mill-contrib-scoverage0.11_2.13/2.1.1/ivys/ivy.xml
    not found: https://repo1.maven.org/maven2/com/lihaoyi/mill-contrib-scoverage0.11_2.13/2.1.1/mill-contrib-scoverage0.11_2.13-2.1.1.pom

Looking at the maven repo, I don't see anything for scoverage and Scala3.

In the Mill git repo, Issue 2043 requests support for Scala3.2. There is a reply that the compiler can generate scoverage info on it's own, but no indication how to form that into a report. Issue 2016 merged some code to support Scala3, but I don't know if it's in a usable state or how to use it.


Solution

  • In the documentation page you linked, you see a scoverageVersion target. That's the place where you should apply your preferred Scoverage version. So the example with your versions applied might look like this:

    import $ivy.`com.lihaoyi::mill-contrib-scoverage:`
    import mill.contrib.scoverage.ScoverageModule
    
    object foo extends ScoverageModule  {
      def scalaVersion = "2.13.14" // or any other Scala version you prefer
      def scoverageVersion = "2.1.1" // or any other Scoverage version you prefer and that supports the set up Scala version
    
      object test extends ScoverageTests with TestModule.ScalaTest {
        def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.0.8")
      }
    }
    

    Since Mill supports various Scala and Scoverage versions, you are supposed to configure your preferred versions in your build setup.

    Your assumption that the issue might be the import statement is wrong. This import:

    import $ivy.`com.lihaoyi::mill-contrib-scoverage:`
    

    means, you want to use the mill-contrib-scoverage Mill plugin in the exact same version as the Mill version you're using. We don't plublish a plugin for each Scoverage version (which would a tremendous amout of work). Instead, you configure the Scoverage version via a configuration target as shown above. It's the same concept you already use to configure the Scala version.

    To use Scala 3, just change the scalaVersion accordingly.

    def scalaVersion = "3.4.2"