pam
pam

Reputation: 1265

java.lang.IncompatibleClassChangeError: the number of constructors

I'm pretty new to Java and I'm trying to get around API testing with rest assured. I tried my code with the following pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yourcompany.restassured</groupId>
    <artifactId>restassuredtest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
    <directory>${project.basedir}/target</directory>
    <outputDirectory>${project.build.directory}/classes</outputDirectory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
    </build>
    <repositories>
        <repository>
            <id>central</id>
            <name>bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-service</artifactId>
            <version>0.13.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libfb303</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libthrift</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.19</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.19</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>0.13.0</version>
        </dependency>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-core</artifactId>
            <version>1.2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>pl.pragmatists</groupId>
            <artifactId>JUnitParams</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>2.4.6</version>
        </dependency>

    </dependencies>
</project>

ending up with this error- java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for com.jayway.restassured.internal.RequestSpecificationImpl$EncodingTarget do not match. Expected -1 but got 2

I googled a lot for a solution, but nothing worked. One of the reasons, according to my understanding is that the rest assured version and groovy version don't match. But I feel the versions are ok in this case. I'm using Java 8, JDK 1.8 on IntelliJ 2016.1.1 I'd really appreciate if you could help me out of this.

Upvotes: 1

Views: 911

Answers (1)

pczeus
pczeus

Reputation: 7867

The Rest Assured FAQ clearly states in it's example that:

Groovy Needs to be the same version that REST Assured depends on

Looking at the maven.pom file for the version of REST Assured you are using (2.9.0), the version of Groovy it depends on is: Groovy 2.4.4. But you have your set to 2.4.6. Change the Groovy version in your pom file to eliminate the issue.

<dependency>
  <groupId>org.codehaus.groovy</groupId>
  <artifactId>groovy-all</artifactId>
  <!-- Needs to be the same version that REST Assured depends on -->
  <version>2.4.3</version>
  <scope>test</scope>
</dependency>

<properties>
    <scm.branch>master</scm.branch>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <groovy.version>2.4.4</groovy.version>
    <gmaven.version>1.5</gmaven.version>
    <hamcrest.version>1.3</hamcrest.version>
    <jackson1.version>1.9.11</jackson1.version>
    <jackson2.version>2.4.3</jackson2.version>
    <maven-javadoc.version>2.9.1</maven-javadoc.version>
</properties>

Upvotes: 2

Related Questions