Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco fails on Gradle 7.0.2 and Kotlin 1.5.10

Today I updated gradle and kotlin dependencies in android studio.

The new versions are these:

kotlin_version = "1.5.10"
...
jacoco {
    toolVersion = "0.8.6"
}
...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

The test coverage report task fails with the following error:

2021-05-27T16:57:49.150+0200 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':consumerkit:testDebugUnitTestCoverage'.
2021-05-27T16:57:49.304+0200 [DEBUG] [org.codehaus.groovy.vmplugin.VMPluginFactory] Trying to create VM plugin `org.codehaus.groovy.vmplugin.v9.Java9` by checking `java.lang.Module`, but failed:
java.lang.ClassNotFoundException: java.lang.Module
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.codehaus.groovy.vmplugin.VMPluginFactory.lambda$createPlugin$0(VMPluginFactory.java:61)
        at java.security.AccessController.doPrivileged(Native Method)
like image 446
Ultimo_m Avatar asked May 27 '21 15:05

Ultimo_m


People also ask

Does JaCoCo work for Kotlin?

The Android-Root-Coverage-Plugin can be used to combine both jUnit and instrumented tests in a Java and/or Kotlin multi module project without any great need to configure anything else. It resolved my following issues: Getting coverage in multi module project.

How do I get Jacoco code coverage report gradle?

Run gradle build jacocoTestReport to generate JaCoCo code coverage report. and then just run gradle build . JaCoCo report will be generated at each build task execution. It works in similar fashion as the previous option, but generates report after every execution of test task.

Which JaCoCo version do I need for Gradle reporting?

Table 1. Gradle defaults for JaCoCo properties The JacocoReport task can be used to generate code coverage reports in different formats. It implements the standard Gradle type Reporting and exposes a report container of type JacocoReportsContainer. Example 4. Configuring test task This feature requires the use of JaCoCo version 0.6.3 or higher.

What version of JaCoCo do I need to run a test?

Configuring test task This feature requires the use of JaCoCo version 0.6.3 or higher. The JacocoCoverageVerification task can be used to verify if code coverage metrics are met based on configured rules.

How do I create a JaCoCo test report in Java?

Applying the JaCoCo plugin If the Java plugin is also applied to your project, a new task named jacocoTestReport is created. By default, a HTML report is generated at $buildDir /reports/jacoco/test. While tests should be executed before generation of the report, the jacocoTestReport task does not depend on the test task.

Which tasks can be enhanced with the JaCoCo plugin?

While all tasks of type Test are automatically enhanced to provide coverage information when the java plugin has been applied, any task that implements JavaForkOptions can be enhanced by the JaCoCo plugin. That is, any task that forks Java processes can be used to generate coverage information.


1 Answers

For Kotlin 1.5 you should use JaCoCo 0.8.7 instead of 0.8.6 - see https://github.com/jacoco/jacoco/pull/1164 and the full changelog at https://www.jacoco.org/jacoco/trunk/doc/changes.html

Example snippet:

// build.gradle or build.gradle.kts
jacoco {
    toolVersion = "0.8.7"
}
like image 72
Godin Avatar answered Oct 16 '22 00:10

Godin