Software Development

How to resolve java.lang.NoClassDefFoundError ImmutableMap when running TestNG suites in Selenium?

MA Asked by Marcus Thorne · 12-10-2025
0 upvotes 15,845 views 0 comments
The question

I am currently setting up a Maven project for automation testing, but every time I trigger my TestNG suite, I encounter the java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error. It seems like a Guava dependency issue, but I have verified my pom.xml multiple times. Has anyone found a definitive way to fix this version mismatch without breaking other dependencies?

3 answers

0
AB
Answered on 14-10-2025

This error almost always stems from a dependency conflict involving the Google Guava library. In modern software development, Selenium and TestNG both rely on Guava, but if different versions are being pulled in via transitive dependencies, the JVM might fail to find the ImmutableMap class at runtime. The most effective fix is to explicitly add the latest Guava dependency to your pom.xml. Alternatively, you can use the Maven Dependency Tree command to identify which library is bringing in an outdated version and exclude it. This ensures that your classpath remains clean and that the class loader finds the correct bytecode during execution.

0
BR
Answered on 16-10-2025

Have you tried running mvn dependency:tree to see if there is a conflict between your Selenium-Java version and another third-party library? Sometimes a simple version exclusion in the pom file is all that's needed, but I'm curious if you've checked for multiple jar versions in your local M2 repository?

CH 18-10-2025

Bradley, checking the local repository is a great shout. Often, Maven fails to refresh the snapshots correctly, leading to corrupted jar files. I'd recommend running mvn clean install -U after deleting the specific Guava folder in the .m2 directory. This forces a fresh download of the artifacts and usually clears up any NoClassDefFound issues that aren't related to actual code errors but rather environment inconsistencies.

0
NA
Answered on 20-10-2025

Usually, this happens because the Guava version is too old. Updating your Selenium dependency to the latest stable version (4.x or higher) typically bundles the correct version of Guava automatically.

NA 21-10-2025

I agree with Natalie. I had this exact same problem last month while upgrading our testing framework. Updating Selenium worked immediately because the newer versions have shifted away from certain Guava dependencies, reducing these types of classpath conflicts significantly.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session