Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException with JacocoPluginExtension

I'm running a build in Azure DevOps with latest gradle (6.8) and I get NPE:

Caused by: java.lang.NullPointerException
    at org.gradle.testing.jacoco.plugins.JacocoPluginExtension.applyTo(JacocoPluginExtension.java:162)
    at org.gradle.testing.jacoco.plugins.JacocoPluginExtension$applyTo.call(Unknown Source)
    at org.akhikhl.gretty.StartBaseTask.initJacoco(StartBaseTask.groovy:156)
    at org.akhikhl.gretty.StartBaseTask.<init>(StartBaseTask.groovy:41)
    at org.akhikhl.gretty.AppStartTask.<init>(AppStartTask.groovy)
    at org.akhikhl.gretty.AppStartTask_Decorated.<init>(Unknown Source)

I have such configuration in build.gradle :

buildscript {
    repositories {
        mavenCentral()
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'jacoco'

group = '*****'
version = '1.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    // my deps
}

test {
    maxParallelForks = 1
    finalizedBy jacocoTestReport
}

jacocoTestReport {
    dependsOn test
}

jacoco {
    toolVersion = "0.8.6"
}

I have such configuration in Azure DevOps pipeline:

- task: Gradle@2
  displayName: 'Build and run unit tests'
  inputs:
    gradleWrapperFile: project-name/gradlew
    workingDirectory: project-name
    testResultsFiles: 'project-name/build/test-results/test/TEST-*.xml'
    sonarQubeRunAnalysis: true
    sonarQubeGradlePluginVersion: 2.6.2

Any ideas why it happens?

like image 740
Rostislav V Avatar asked Dec 05 '25 10:12

Rostislav V


1 Answers

As see be seen from the stack trace, the NullPointerException happens when the Gretty plugin tries to configure the JaCoCo plugin.

Gradle is moving very fast and APIs are often deprecated and removed at least one major version later (e.g. deprecated in 5.0 and removed in 6.0). There is often about one to two years for buildscript and plugin authors to react to these deprecations.

Though you don't mention it, I am quite sure you are using a more than three year old version of the original Gretty plugin:

enter image description here

At least I can reproduce the issue and the same stack trace using that version.

Though it looks like it was abandoned years ago, this isn't the case. Instead, the plugin has been forked and moved to a new namespace (from org.akhikhl.gretty to org.gretty):

enter image description here

There is even a bug report describing the NullPointerException issue (going all the way back to Gradle 4.6).

So to fix it, change the Gretty plugin ID to the new namespace and use a recent version:

plugins {
  id "org.gretty" version "3.0.3"
}
like image 57
Bjørn Vester Avatar answered Dec 07 '25 14:12

Bjørn Vester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!