3

I am using GraphQL on a Java project and it was working on a server. When I changed to another server, it stopped working and it is throwing the following exception:

java.lang.NoSuchMethodError: graphql.execution.ExecutionStrategy.(Lgraphql/execution/DataFetcherExceptionHandler;)V at graphql.execution.AbstractAsyncExecutionStrategy.(AbstractAsyncExecutionStrategy.java:19) at graphql.execution.AsyncExecutionStrategy.(AsyncExecutionStrategy.java:23) at graphql.GraphQL$Builder.(GraphQL.java:199) at graphql.GraphQL.newGraphQL(GraphQL.java:166)

I am using exactly the same Java version (1.8.0_181), the same graphql-java dependency version (7.0) and the same project version.

Am I missing something? Anyone with the same problem?

Thanks in advance,

Solution

After analyzing the dependencies of each one of my project dependencies, I noticed graphql-java-annotations was importing version 3.0 of graphql-java library. graphql-java library is one of my project dependencies as mentioned before (was using version 7.0).

As consequence, two different versions of graphql-java where being referenced and were conflicting with each other.

To solve this issue, I removed graphql-java dependency and I started using only the version imported on graphql-java-annotations.

1 Answers1

1

Usually this is because dependency confliction.

You can add this to your pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerArgs>
                    <arg>-verbose</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

then try package your application, it will log which jar the graphql.execution.ExecutionStrategy class is loaded from. Then you can check if it is the correct version.

xingbin
  • 27,410
  • 9
  • 53
  • 103
  • Did the suggested change to the pom and checked from which jar the `graphql.execution.ExecutionStrategy` is being imported. The jar used is graphql-java-7.0, which is correct. The output on maven package: `[loading ZipFileIndexFileObject[.m2/repository/com/graphql-ja va/graphql-java/7.0/graphql-java-7.0.jar(graphql/ExecutionResult.class)]]` Any suggestion? – José Miguel Melo Sep 04 '18 at 15:39
  • @JoséMiguelMelo Maybe you can try update the version to `9.2` – xingbin Sep 04 '18 at 17:46
  • I solved the problem and added the solution to the question. One little question: As referenced on the solution, I had graphql-java (v7.0) and graphql-java-annotation libraries as dependencies. The last one had as dependency graphql-java (v3.0). Graphql-java versions were conflicting with each other. Shouldn't the inner dependency be replaced with the one specified on my project pom.xml? – José Miguel Melo Sep 05 '18 at 11:06
  • @JoséMiguelMelo Not an expert, but maybe can solve it. https://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven – xingbin Sep 05 '18 at 11:46