jacocoTestReport FAILED – Could not create service of type IsolatedAntBuilder

Error

You might have seen the following error in your Jenkins pipeline while trying to build the job after you commit some changes in your code repository:

* What went wrong:
Execution failed for task ':aircraft-model:jacocoTestReport'.
> Could not create service of type IsolatedAntBuilder using BuildScopeServices.createIsolatedAntBuilder().
   > Could not inspect the Groovy system for ClassLoader VisitableURLClassLoader(ant-and-gradle-loader)
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':aircraft-model:jacocoTestReport'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:188)
	at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
        ...

The above error might have occurred due to the version incompatibility between Jacoco, Gradle and Java. For example, you are trying to upgrade your Java version to 17.

A migration From Java 7 to later JDK release might cause the issue, because of modularization happened in JDK 9. Code that uses JDK-internal APIs should continue to run but should be migrated to use supported APIs. Some APIs have been made inaccessible, removed or altered in the default behavior, and you might encounter issues when compiling or running your application. You can run Jacoco locally without any problems but once your pipeline starts, the build fails with the error.

Migrating From JDK 8 to Later JDK release, in this case its Illegal Reflective access. If you want to enable deep reflection to access nonpublic members, then use the following runtime option.

--add--options

This option allows module to open package to target-module, regardless of module declaration. If the target module is ALL_UNNAMED then the source package is exported to all unnamed modules, whether they exist internally or created later on.

--add-opens<source-module>/<package>=<target-module>

Solution

Adding the following in your gradle.properties fixes the issue:

org.gradle.jvmargs= --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED -add-opens=java.base/java.lang=ALL-UNNAMED

Or

org.gradle.jvmargs= --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

That’s all about how to fix the jacocoTestReport failure.

Share

Related posts

No comments

Leave a comment