javaseleniumselenium-webdriverrest-assuredrest-assured-jsonpath

Getting an error Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache


getting an error while executing the Rest Assured program

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
    at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
Response response = RestAssured.get("https://reqres.in/api/users/2");
Assert.assertEquals(response.getStatusCode(), 200);

Code Maven Dependency


Solution

  • Add this dependency and remove all other rest assured dependencies. json-path is already included in rest-assured dependency.

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>5.2.0</version>
        <scope>test</scope>
    </dependency>
    

    If you need schema validator you can add:

    <!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>5.2.0</version>
        <scope>test</scope>
    </dependency>
    
    

    Make sure you have JDK/JAVA_HOME env variable properly installed. The abouve depedencies should work with JDK 8+