存在guava-18.0.jar仍遇hibernate-ogm-cassandra NoClassDefFoundError问题求助
Hey there! Let's break down why you're hitting this NoClassDefFoundError: com/google/common/util/concurrent/AsyncFunction error even though Guava 18.0 is in your Maven dependencies, and walk through fixes to get it sorted:
Common Causes & Solutions
1. Hidden Dependency Conflicts
Even if you’ve explicitly added Guava 18.0, another dependency in your project might be pulling in an older or incompatible version of Guava. Maven could be resolving to that conflicting version instead of your 18.0 jar, and that older version might not include the AsyncFunction class.
Fix:
Run this Maven command to inspect your full dependency tree and spot Guava version clashes:
mvn dependency:tree | grep guava
If you see conflicting versions, try either of these:
- Exclude the unwanted Guava from the problematic dependency in your
pom.xml:<dependency> <groupId>[offending-group-id]</groupId> <artifactId>[offending-artifact-id]</artifactId> <version>[version]</version> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> </exclusions> </dependency> - Use Maven’s
dependencyManagementsection to lock in the Guava version you need (this ensures all dependencies use your specified version):<dependencyManagement> <dependencies> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>18.0</version> <!-- Or a higher compatible version if needed --> </dependency> </dependencies> </dependencyManagement>
2. Guava Version Incompatibility with Hibernate OGM Cassandra
Guava 18.0 might not be the right match for your specific Hibernate OGM Cassandra release. Some versions of Hibernate OGM require newer Guava builds where AsyncFunction or related classes are properly supported (or have no breaking API changes).
Fix:
Check the official Hibernate OGM documentation for your version to find the recommended Guava version. For example, if you’re using Hibernate OGM 5.4.x, you might need Guava 20.0 or later. Update your Guava dependency to match that recommended version.
3. Corrupted Maven Cache
Sometimes the cached Guava jar in your local Maven repository is corrupted, leading to missing classes even though the dependency is listed correctly.
Fix:
Clean your Maven cache and rebuild the project to refresh dependencies:
mvn clean install -U
The -U flag forces Maven to update all dependencies and clear stale cache entries.
4. IDE Runtime Classpath Discrepancies
If you’re running your app in an IDE like IntelliJ or Eclipse, the runtime classpath might not be including the Guava jar properly. IDEs can sometimes have mismatches between the Maven dependency tree and what’s actually loaded at runtime.
Fix:
- Refresh your Maven project in the IDE (look for a "Reload All Maven Projects" option).
- Check the IDE’s runtime classpath settings to ensure Guava 18.0 is listed and enabled.
内容的提问来源于stack exchange,提问作者Emma

