kordamp / kordamp-gradle-plugins

A collection of Gradle plugins
https://kordamp.org/kordamp-gradle-plugins/
Apache License 2.0
138 stars 25 forks source link

[jacoco] Using exclusion causes NPE #446

Closed zarebski-m closed 3 years ago

zarebski-m commented 3 years ago

Setting jacoco exclusion in child project causes NPE. I am using Kotlin DSL. Latest Kordamp version (0.43.0).

Example configuration:

config {
    coverage {
        jacoco {
            excludes = setOf("**/com/example/foo/bar/**")
        }
    }
}

This results in:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':example'.
> Cannot invoke method setFrom() on null object

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':example'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
        [...]
Caused by: java.lang.NullPointerException: Cannot invoke method setFrom() on null object
        at org.kordamp.gradle.plugin.jacoco.JacocoPlugin.adjustClassDirectories(JacocoPlugin.groovy:382)
        at jdk.internal.reflect.GeneratedMethodAccessor4030.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.kordamp.gradle.plugin.jacoco.JacocoPlugin$_configureJacocoReportTask_closure4.doCall(JacocoPlugin.groovy:285)
        [...]

I suspect that the issue might be caused by https://github.com/kordamp/kordamp-gradle-plugins/blob/c914d314b5978199331599c297789fd828ccd5dd/plugins/jacoco-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/jacoco/JacocoPlugin.groovy#L382 – shouldn't there be t.additionalClassDirs (property) instead of t.additionalClassDirs() (method call)?

Build environment:

$ ./gradlew --version

------------------------------------------------------------
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:          11.0.10 (AdoptOpenJDK 11.0.10+9)
OS:           Windows 10 10.0 amd64
aalmiray commented 3 years ago

Ah good catch. Code completion screwed me over. Also, I didn't double check trusting the IDE.