In Gradle I got stumped by this even though class YYYYYY was on the classpath.
java.lang.NoClassDefFoundError: Could not initialize class YYYYYY
I put a try catch block around the code that was failing. This gave me a more direct error than before.
It turned out that I had XML reading error where a class was trying to read a file that was not present on the classpath
The class was present but the initialization failed, check your setup.