scoverage / gradle-scoverage

A plugin to enable the use of Scoverage in a gradle Scala project
Apache License 2.0
53 stars 38 forks source link

scoverage 7.0.0 plugin fails checkScoverage call with java.lang.AbstractMethodError #173

Open pra91 opened 3 years ago

pra91 commented 3 years ago

When using 7.0.0 of the plugin I am unable to run checkScoverage in my builds.

running ./gradlew checkScoverage runs my test cases but then fails with the following stacktrace. Running reportScoverage works as expected

Caused by: java.lang.AbstractMethodError
        at org.scoverage.ScoveragePlugin$_configureCheckTask_closure8$_closure46$_closure47.doCall(ScoveragePlugin.groovy:349)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.doExecute(AbstractTask.java:681)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.lambda$execute$0(AbstractTask.java:668)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication.reapply(DefaultUserCodeApplicationContext.java:86)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:668)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:643)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.run(ExecuteActionsTaskExecuter.java:494)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
...

Gradle file:

plugins {
    id 'scala'
    id 'java-library'
    id 'com.github.johnrengelman.shadow' version '6.1.0'
    id 'cz.alenkacz.gradle.scalafmt' version '1.16.2'
    id "org.scoverage" version "7.0.0" 
    id 'io.github.cosmicsilence.scalafix' version '0.1.9'
    id "com.google.protobuf" version "0.8.16"
}
...

ext {
    scalaVersion = "2.12"
    sparkVersion = "3.1.1"
    deltaVersion = "1.0.0"
    akkaVersion = "2.6.8"
    akkaHttpVersion = "10.2.3"
    scalapbVersion = "0.11.0"
}
...

dependencies {

    compileOnly "org.scala-lang:scala-library:2.12.10"
...
    testImplementation "org.scalatest:scalatest_${scalaVersion}:3.2.2"
    testImplementation "org.scalatestplus:junit-4-13_${scalaVersion}:3.2.2.0"
    testImplementation "org.mockito:mockito-scala-scalatest_${scalaVersion}:1.16.29"
}

scoverage {
    check {
        minimumRate = 0.5
    }
}

scalafix {
    configFile = file("./.scalafix.conf")
    ignoreSourceSets = ["scoverage"]
}
eyalroth commented 3 years ago

When using the syntax for multiple checks, one has to specify the coverage type:

scoverage {
    check {
        minimumRate = 0.5
        coverageType = CoverageType.Statement
    }
}

If no multiple checks are required, then it is possible to specify just the minimum rate:

scoverage {
    minimumRate = 0.5
}

If the problem still persists after fixing the syntax, please add the output ./gradlew --version as well.

pra91 commented 3 years ago

I am still having the same problem with

scoverage {
    minimumRate = 0.5
}

gradle output below:

------------------------------------------------------------
Gradle 6.8
------------------------------------------------------------

Build time:   2021-01-08 16:38:46 UTC
Revision:     b7e82460c5373e194fb478a998c4fcfe7da53a7e

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_302 (Amazon.com Inc. 25.302-b08)
OS:           Mac OS X 11.6 x86_64
eyalroth commented 3 years ago

I was able to reproduce the issue and it seems to be a problem with moving from Gradle 6 to 7.

Running a sample project with Gradle 6.8 and AdoptOpenJDK 11 yields the error:

Caused by: java.lang.AbstractMethodError: Receiver class org.scoverage.ScoverageExtension$CheckConfig does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
        at org.scoverage.ScoveragePlugin$_configureCheckTask_closure8$_closure46$_closure47.doCall(ScoveragePlugin.groovy:343)

Upgrading to Gradle 7 in the project resolves the issue; alternatively, using the plugin version before 6 also seems to resolve the issue.

It looks like moving the plugin to be built with Gradle 7 instead of 6, which was included in version 6 of the plugin (see diff between 5 and 6), broke the plugin for builds with Gradle version less than 7.

This looks to be a problem with Gradle as can be seen in other plugins here and here.

I'll see about opening a ticket in the Gradle repository. For now, @pra91, can you upgrade your Gradle to 7 and see if it helps?