java.lang.IncompatibleClassChangeError:构造函数的数量

时间:2016-04-06 00:25:27

标签: java maven intellij-idea groovy java-8

我对Java很陌生,我正试着放心地进行API测试。 我用以下pom文件尝试了我的代码:

<?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>

以此错误结束 - java.lang.IncompatibleClassChangeError:com.jayway.restassured.internal.RequestSpecificationImpl $ EncodingTarget的运行时和编译时的构造函数数量不匹配。预期-1但得到2

我搜索了很多解决方案,但没有任何效果。其中一个原因,根据我的理解是,放心的版本和groovy版本不匹配。但我觉得在这种情况下版本还可以。我在IntelliJ 2016.1.1上使用Java 8,JDK 1.8 如果你能帮我解决这个问题,我真的很感激。

1 个答案:

答案 0 :(得分:1)

Rest Assured FAQ在其示例中明确指出:

Groovy需要与REST Assured所依赖的版本相同

查看maven.pom文件以获取正在使用的REST Assured版本(2.9.0),它所依赖的Groovy版本是: Groovy 2.4.4 。但是你的设置为2.4.6。更改pom文件中的Groovy版本以消除此问题。

<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>