approvals / ApprovalTests.Java

ApprovalTest verification library for Java
Apache License 2.0
337 stars 74 forks source link

`NoSuchMethod` when running ApprovalTests on Java 8 #546

Closed rohanKanojia closed 1 month ago

rohanKanojia commented 2 months ago

Hello, we use ApprovalTests in Fabric8 Kubernetes Client

We wanted to merge pull request by dependabot for bumping approval tests to v24.4.0 https://github.com/fabric8io/kubernetes-client/pull/6255

However, we noticed that Approval tests are no longer running on JDK8 properly, currently we're seeing this error:

logs from GitHub Action

Error:    CRDGeneratorApprovalTest.apiV1ApprovalTest:92 » NoClassDefFound Could not initialize class org.approvaltests.reporters.DefaultFrontLoadedReporter
org.approvaltests.reporters.DefaultFrontLoadedReporter
Error:    CRDGeneratorApprovalTest.apiV2ApprovalTest:118 » NoSuchMethod java.util.Map.entry(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map$Entry;

Javadoc for Map.entry(Object, Object) says it's introduced since Java 9. However, I'm not able to find any references to this method in your codebase.

Same test completes successfully on JDK11 and JDK17.

I wanted to check if this change was intentional in a minor release. Is support for Java8 dropped from ApprovalTests?

LarsEckart commented 2 months ago

I'll have a look. We still want to be compatible with jdk8, even though right now our pipelines don't use it. The eclipse code formatter maven plugin is the reason for this, as their latest versions requrie at least jdk 11 and from what it looks like, soon 21 https://code.revelc.net/formatter-maven-plugin/eclipse-versions.html

LarsEckart commented 2 months ago

Another finding. We bumped jakarta-servlet-api and that also has:

Minimum Java SE Version Java SE 17 or higher

@isidore this is used in approvaltests-util in ServletContextLoader.

LarsEckart commented 2 months ago

Found another one:

TestNG v7.6.0 and above: JDK 11 or higher.

if we have such dependencies (even when marked optional I think), we cannot compile with jdk 8 (and find such issues)

LarsEckart commented 2 months ago

When I rip out all those dependencies, I can compile our project with jdk8, only aprovaltests-tests doesnt work because well, there we really started using later APIs and thos bumped the dependency on this project.

[INFO] ApprovalTests.Java ................................. SUCCESS [  0.159 s]
[INFO] approvaltests-util ................................. SUCCESS [  3.117 s]
[INFO] approvaltests ...................................... SUCCESS [  1.159 s]
[INFO] approvaltests-util-tests ........................... SUCCESS [  0.117 s]
[INFO] approvaltests-tests ................................ FAILURE [  0.219 s]
rohanKanojia commented 2 months ago

@LarsEckart : Thanks for your swift response. Is it okay to say that ApprovalTests no longer support Java8? We currently use ApprovalTests v24.3.0 and it is building on JDK8 . Something has changed since v24.3.0 , ApprovalTests are no longer working on JDK8 for us.

LarsEckart commented 2 months ago

We'll discuss this, so far we wanted to stay jdk8 compatible and I consider this rather an unfortunate mistake. I'll get back to you if we bump the min jdk or if we verify all our dependencies to be able to stay on 8.

LarsEckart commented 1 month ago

Please give version 24.5.0 a try, it should work again on jdk 8.

manusa commented 1 month ago

Please give version 24.5.0 a try, it should work again on jdk 8.

This is working now, thanks!

https://github.com/fabric8io/kubernetes-client/pull/6349