1

I am trying to get some reports with the code coverage information for my project. I found that scoverage-maven-plugin produce xml files covering the % of the different modules that the unit test cases have covered so far.

So I tried to add that plugin in my pom, but I am getting the following error:

[ERROR] error: java.lang.NoSuchMethodError: 'scala.tools.nsc.reporters.Reporter scala.tools.nsc.Global.reporter()'
[INFO]  at scoverage.ScoverageInstrumentationComponent$$anon$1.run(plugin.scala:115)
[INFO]  at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1514)
[INFO]  at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1498)
[INFO]  at scala.tools.nsc.Global$Run.compileSources(Global.scala:1491)
[INFO]  at scala.tools.nsc.Global$Run.compile(Global.scala:1620)
[INFO]  at scala.tools.nsc.Driver.doCompile(Driver.scala:47)
[INFO]  at scala.tools.nsc.MainClass.doCompile(Main.scala:32)
[INFO]  at scala.tools.nsc.Driver.process(Driver.scala:67)
[INFO]  at scala.tools.nsc.Driver.main(Driver.scala:80)
[INFO]  at scala.tools.nsc.Main.main(Main.scala)
[INFO]  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
[INFO]  at java.base/java.lang.reflect.Method.invoke(Method.java:577)
[INFO]  at scala_maven_executions.MainHelper.runMain(MainHelper.java:164)
[INFO]  at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)
[INFO] java.lang.reflect.InvocationTargetException
[INFO]  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
[INFO]  at java.base/java.lang.reflect.Method.invoke(Method.java:577)
[INFO]  at scala_maven_executions.MainHelper.runMain(MainHelper.java:164)
[INFO]  at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)
[ERROR] Caused by: java.lang.NoSuchMethodError: 'scala.tools.nsc.reporters.Reporter scala.tools.nsc.Global.reporter()'
[INFO]  at scoverage.ScoverageInstrumentationComponent$$anon$1.run(plugin.scala:115)
[INFO]  at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1514)
[INFO]  at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1498)
[INFO]  at scala.tools.nsc.Global$Run.compileSources(Global.scala:1491)
[INFO]  at scala.tools.nsc.Global$Run.compile(Global.scala:1620)
[INFO]  at scala.tools.nsc.Driver.doCompile(Driver.scala:47)
[INFO]  at scala.tools.nsc.MainClass.doCompile(Main.scala:32)
[INFO]  at scala.tools.nsc.Driver.process(Driver.scala:67)
[INFO]  at scala.tools.nsc.Driver.main(Driver.scala:80)
[INFO]  at scala.tools.nsc.Main.main(Main.scala)
[INFO]  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
[INFO]  ... 3 more

Not able to find from where I should get scala.tools.nsc.reporters.Reporter scala.tools.nsc.Global.reporter()

The full pom is:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mygroupid</groupId>
    <artifactId>myartifact</artifactId>
    <version>1.0.0</version>
    <name>myproject</name>

    <properties>
        <app.build.version>1.0.0</app.build.version>
        <encoding>UTF-8</encoding>
        <scala.version>2.12.14</scala.version>
        <scala.compat.version>2.12</scala.compat.version>
        <scala.binary.version>2.12</scala.binary.version>
        <spark.version>3.2.1</spark.version>
        <scope.value>provided</scope.value>
        <scoverage.plugin.version>1.3.0</scoverage.plugin.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_${scala.binary.version}</artifactId>
            <version>${spark.version}</version>
            <scope>${scope.value}</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_${scala.binary.version}</artifactId>
            <version>${spark.version}</version>
            <scope>${scope.value}</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-hive_${scala.binary.version}</artifactId>
            <version>${spark.version}</version>
            <scope>${scope.value}</scope>
        </dependency>

        <dependency>
            <groupId>io.delta</groupId>
            <artifactId>delta-core_2.12</artifactId>
            <version>2.0.0</version>
            <scope>${scope.value}</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-streams</artifactId>
            <version>3.1.2</version>
            <scope>${scope.value}</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql-kafka-0-10_${scala.binary.version}</artifactId>
            <version>${spark.version}</version>
            <scope>${scope.value}</scope>
        </dependency>

        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.12</artifactId>
            <version>3.2.14</version>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <build>
        <finalName>myproject-${app.build.version}</finalName>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>

            <plugin>
                <groupId>org.scoverage</groupId>
                <artifactId>scoverage-maven-plugin</artifactId>
                <version>${scoverage.plugin.version}</version>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <highlighting>true</highlighting>
                    <aggregate>true</aggregate>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <phase>test</phase>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <id>Scaladoc</id>
                        <goals>
                            <goal>doc</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <args>
                                <arg>-no-link-warnings</arg>
                            </args>
                        </configuration>
                    </execution>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>doc-jar</goal>
                        </goals>
                    </execution>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                        <configuration>
                            <args>
                                <arg>-dependencyfile</arg>
                                <arg>${project.build.directory}/.scala_dependencies</arg>
                            </args>
                            <jvmArgs>
                                <jvmArg>-Xss4m</jvmArg>
                                <jvmArg>-Xms512m</jvmArg>
                                <jvmArg>-Xmx4096m</jvmArg>
                            </jvmArgs>
                            <scalaVersion>${scala.version}</scalaVersion>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <junitxml>.</junitxml>
                    <filereports>WDF TestSuite.txt</filereports>
                    <htmlreporters>${project.build.directory}/html/scalatest</htmlreporters>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

Edits after @Dmytro feedback:

I added in the pom the following dependencies:

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
        </dependency>

        <dependency>
            <groupId>org.scoverage</groupId>
            <artifactId>scalac-scoverage-plugin_2.12</artifactId>
            <version>1.4.1</version>
        </dependency>

And changed the scope to

<scope.value>compile</scope.value>

But I am still getting the error: java.lang.NoSuchMethodError: 'scala.tools.nsc.reporters.Reporter scala.tools.nsc.Global.reporter()'

Ignacio Alorre
  • 7,307
  • 8
  • 57
  • 94
  • `NoSuchMethodError` https://stackoverflow.com/questions/35186/how-do-i-fix-a-nosuchmethoderror https://stackoverflow.com/questions/8168052/java-lang-nosuchmethoderror-when-the-method-definitely-exists https://stackoverflow.com/questions/59706633/nosuchmethoderror-java https://stackoverflow.com/questions/67777305/exception-in-thread-jobgenerator-java-lang-nosuchmethoderror-scala-collectio – Dmytro Mitin Feb 16 '23 at 12:11
  • *"Not able to find from where I should get `scala.tools.nsc.reporters.Reporter scala.tools.nsc.Global.reporter()`"* The package `scala.tools.nsc` is from `scala-compiler` dependency https://mvnrepository.com/artifact/org.scala-lang/scala-compiler – Dmytro Mitin Feb 16 '23 at 12:13
  • @DmytroMitin hi, the issues is I am not able to find what dependency is required for scoverage-maven-plugin to include scala.tools.nsc.reporters.Reporter in my project. The project was compiling fine until I added that plugin in the pom – Ignacio Alorre Feb 16 '23 at 12:14

1 Answers1

2

Could you try to add

<dependency>
    <groupId>org.scala-lang</groupId>
    <artifactId>scala-compiler</artifactId>
    <!--<version>2.12.14</version>-->
    <version>${scala.version}</version>
</dependency>

?

https://mvnrepository.com/artifact/org.scala-lang/scala-compiler

Does this change anything for you?


scoverage-maven-plugin 1.3.0 depends on scalac-scoverage-plugin 1.3.0

https://github.com/scoverage/scoverage-maven-plugin/blob/scoverage-maven-plugin-1.3.0/pom.xml#L93-L101

scalac-scoverage-plugin 1.3.0 depends on scala-compiler 2.12.0

https://index.scala-lang.org/scoverage/scalac-scoverage-plugin/artifacts/scalac-scoverage-plugin/1.3.0

https://github.com/scoverage/scalac-scoverage-plugin/blob/v1.3.0/build.sbt#L89

https://github.com/scoverage/scalac-scoverage-plugin/blob/v1.3.0/build.sbt#L15

scala-compiler is marked as provided in the dependencies of scalac-scoverage-plugin so should be added manually when needed.

The method scala.tools.nsc.Global.reporter() returns Reporter in scala-compiler 2.12.0 https://github.com/scala/scala/blob/v2.12.0/src/compiler/scala/tools/nsc/Global.scala#L1581 (it seems in 2.12.0 there is no scala.tools.nsc.Global.reporter(), it appears in 2.12.5). In 2.12.14 the signature is different, the method returns FilteringReporter https://github.com/scala/scala/blob/v2.12.14/src/compiler/scala/tools/nsc/Global.scala#L1748 https://github.com/scala/scala/blob/v2.12.14/src/compiler/scala/tools/nsc/Global.scala#L90 So the issue seems to be in the combination of versions scalac-scoverage-plugin 1.3.0 + scala-compiler 2.12.14.

Try to either upgrade scoverage-plugin or downgrade Scala version so that the signature of the method is the same (returning either Reporter both times or FilteringReporter both times). The signature changed in 2.12.12 -> 2.12.13 (Reporter -> FilteringReporter) https://github.com/scala/scala/blob/v2.12.12/src/compiler/scala/tools/nsc/Global.scala#L90 https://github.com/scala/scala/blob/v2.12.13/src/compiler/scala/tools/nsc/Global.scala#L90 If you're on scoverage-plugin 1.4.1 can you change Scala to 2.12.12?


Try then to downgrade the scala version:

<properties>
    <scala.version>2.12.12</scala.version>
    ...
</properties>

in combination with

<dependency>
    <groupId>org.scoverage</groupId>
    <artifactId>scalac-scoverage-plugin_2.12</artifactId>
    <version>1.4.1</version>
</dependency>
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
  • Hi, Just tried, but the error is still there – Ignacio Alorre Feb 16 '23 at 12:20
  • I tired adding as well scala-library as dependency. But not success. – Ignacio Alorre Feb 16 '23 at 12:31
  • @IgnacioAlorre Did you add `scala-compiler` as a `compile` dependency, not `provided`? – Dmytro Mitin Feb 16 '23 at 13:10
  • 1
    +1 for all this information. I will try it Tomorrow at my system. I will accept the answer indicating you what worked for me. Thanks a lot for your time – Ignacio Alorre Feb 16 '23 at 17:16
  • I edited the question with the solutions you proposed, but still same error. Not sure if I will need to go to a 2.X version of the scalac-scoverage-plugin – Ignacio Alorre Feb 17 '23 at 07:46
  • @IgnacioAlorre Well, I can see what you did is changing scoverage-plugin version to 1.4.1. But scoverage-plugin 1.4.1 uses scala-compiler 2.12.8 https://github.com/scoverage/scalac-scoverage-plugin/blob/v1.4.1/build.sbt#L91 https://github.com/scoverage/scalac-scoverage-plugin/blob/v1.4.1/build.sbt#L13 And in scala-compiler 2.12.8 the method `scala.tools.nsc.Global.reporter()` still returns `Reporter` while your Scala version is 2.12.14 where the method returns `FilteringReporter` https://github.com/scala/scala/blob/v2.12.14/src/compiler/scala/tools/nsc/Global.scala#L90 – Dmytro Mitin Feb 17 '23 at 09:05
  • @IgnacioAlorre So you didn't fix the version mismatch. Please, as I recommended, either upgrade scoverage-plugin or downgrade Scala version so that the signature of the method is the same (returning either `Reporter` both times or `FilteringReporter` both times). The signature changed in 2.12.12 -> 2.12.13 (`Reporter` -> `FilteringReporter`) https://github.com/scala/scala/blob/v2.12.12/src/compiler/scala/tools/nsc/Global.scala#L90 https://github.com/scala/scala/blob/v2.12.13/src/compiler/scala/tools/nsc/Global.scala#L90 If you're on scoverage-plugin 1.4.1 can you change Scala to 2.12.12? – Dmytro Mitin Feb 17 '23 at 09:11
  • 1
    Thanks @Dmytro, using the combination and coverage-plugin 1.4.1 can you change Scala to 2.12.12 worked for me. I will add in your answer the combination that finally worked out – Ignacio Alorre Feb 17 '23 at 10:02