T
TBD4mo ago
ALR

Fixing Version Issues HOWTO 🧵

Fixing Version Issues HOWTO 🧵
3 Replies
ALR
ALR4mo ago
Team, I'll be out tomorrow. As you're writing more Kotlin tests, you may come across more NoClassDefFoundErrors and ClassNotFoundExceptions. Here's a primer on how to debug and address it. I'll use a familiar example. 1. Identify the class in question. This is easy. It's in the error:
java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/JacksonFeature
java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/JacksonFeature
So there's something amiss with com.fasterxml.jackson.core.util.JacksonFeature.
ALR
ALR4mo ago
2. Find the Maven artifact that this lives in. This is usually something I Google. For instance the search "com.fasterxml.jackson.core.util.JacksonFeature maven" gives you a quick answer:
No description
ALR
ALR4mo ago
3. From Googling, you find the package in question. In this example it's com.fasterxml.jackson.core:jackson-core. So now we're gonna ask Maven to let us know how it's resolving the version for this dependency. That's done using the Maven dependency plugin. Set your current working directory to developer.tbd.website/site/testsuites/testsuite-kotlin. From there, run: $> ./mvnw dependency:tree -Dincludes=$groupId:$artifactId -Dverbose=true ...replacing $groupId and $artifactId above with the right values, so again, in our example it'd be: mvn dependency:tree -Dincludes=com.fasterxml.jackson.core:jackson-core -Dverbose=true 4. The same command with the -Dverbose=true omitted will show you only what version the dependency resolved to, and through what dep path. 5. So the trick here is to identify the right version we want. If you look through the verbose dep tree, you'll see how other components have dependencies on this, and what versions they're using. So for instance if you're calling a DID operation, what version of the dep is web5-kt:credentials declaring and expecting? Make note of this version. 6. Now we're going to lock our build to enforce this version you've identified. That's done in the dependencyManagement section of the pom.xml. If you add a dependency there alongside where I've put jackson-core, Maven will respect the version you've enforced and use it. 7. You can validate you did it right by running dependency:tree again without the verbose flag, and you should see the version you put in the dependencyManagement section. 8. Run your tests again. ./mvnw clean verify from the working directory I noted above, or pnpm test:kotlin from the root of the dev site repo. If it worked, GREAT! If not, try another version!