简体   繁体   中英

Solve Error java.lang.NoSuchMethodError: org.codehaus.groovy.ast.ModuleNode.getStarImports()Ljava/util/List;

I am encountering this exception.

Exception :java.lang.NoSuchMethodError: org.codehaus.groovy.ast.ModuleNode.getStarImports()Ljava/util/List;

I have tried various version of groovy jars like groovy 1.8.4, groovy 1.8.6 etc. But I am not able to get rid of this error.

This happened to me when I had 2 different versions of Groovy in the classpath at the same time. Check your classpath especially if using something that obfuscates it such as Eclipse or Maven.

In my specific case, I was trying to use Groovy 1.8.6 but a Maven dependency was dragging in 1.6.5 causing errors. It worked fine running unit tests on the command line, but not from within Eclipse.

To compile with Groovy 2.x, try adding this to the gmaven plugin element:

<configuration>
    <providerSelection>2.0</providerSelection>
    <source>2.0</source>
</configuration>

For example:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generateStubs</goal>
                        <goal>compile</goal>
                        <goal>generateTestStubs</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <providerSelection>2.0</providerSelection>
                <source>2.0</source>
            </configuration>
        </plugin>
    </plugins>
</build>

with

<dependencies>  
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.1.9</version>
    </dependency>
</dependencies>

seems to work.

我刚刚通过刷新IntelliJ中的所有Gradle项目并再次运行来解决这个问题。

The issue is definitely with multiple groovy versions. I was facing this issue with maven project and Eclipse IDE. In my case, pom.xml had the following -

        <dependencies>
            <dependency>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.0</version>
            </dependency>
        </dependencies>

But in Eclipse Under Window -> preference -> groovy version was 2.5.0. I downgraded it to 2.3.11 and it worked. Just click on switch to use a lower version of Groovy in Eclipse.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM