jwtk/jjwt

NoSuchMethodError when using libraries built against older jjwt version

allantodd opened this issue · 2 comments

Describe the bug
Libraries built against older versions of jjwt cannot be used with version 0.12.5. The following error occurs

java.lang.NoSuchMethodError: 'io.jsonwebtoken.JwtBuilder io.jsonwebtoken.JwtBuilder.setIssuer(java.lang.String)'

We are seeing this problem when trying to upgrade our jjwt version because we use the Twilio SDK com.twilio.sdk::twilio which is built against version 0.11.2

I think this is because setIssuer has moved to io.jsonwebtoken.ClaimsMutator.

So while old code can be built against version 0.12.5 and run okay, if the code is not rebuilt (because it is a library) it fails. This makes it impossible to use libraries built against different jjwt versions in the same project or to upgrade the jjwt version.

To Reproduce

  1. Download and extract jjwt-twilio-nosuchmethoderror.zip
  2. Run mvn compile exec:java -Dexec.mainClass=org.example.Main
  3. NoSuchMethodError occurs

Expected behavior
Code runs okay

Screenshots
NoSuchMethodError

Thanks for reaching out @allantodd!

This is expected, there were some braking changes in 0.12, see the notes in the change log, especially the bits about prepping for the 1.0 release.

You basically have two options in the short term:

  • Wait for Twilio to update it's version
  • Shade/relocate the JJWT classes if you require multiple versions on the classpath. (this is not unique to JJWT)

Thanks @bdemers for the detailed reply