Groovy ShortTypeHandling ClassNotFoundException
Asked Answered
R

7

35

I have a groovy application that uses groovy version 2.2.1. My groovy app was previously running fine but has recently started throwing this exception:

    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.app.Main.main(Main.groovy:83)Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.typehandling.ShortTypeHandling
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

The ShortTypeHandling class was not even introduced until groovy 2.3.0. How can it be referenced in a groovy app running version 2.2.1? I can solve this problem by replacing the groovy-all-2.2.1.jar with groovy-all-2.3.0.jar in my pom but that doesn't root cause the issue.

Robinson answered 24/5, 2014 at 15:24 Comment(3)
I just started playing with Grails 2.4 which uses groovy 2.3.0, and ran across a ShortTypeHandling ClassNotFoundException when I moved the project over to use the Maven plug-in. This is my first time coming across this issue as well and I haven't quite identified the source. I suspect maybe groovy 2.3.0 is coming in through one of your plugin dependencies? Have you added a new one or upgraded one recently? What version of the maven plugin are you using?Teagan
I thought that it had to be a mvn dependency bringing in the groovy-all-2.3.0 jar as well. I did a mvn dependency tree on the entire pom (mvn dependency:tree -Dverbose) and didn't see any reference to groovy 2.3.0. One last thing, the app works great when it runs inside Intellj (which has no groovy 2.3.0 dependencies). The problem only surfaces when I compile/package/run via mvn command line.Robinson
Sorry, you asked about versions, I'm using the groovy-eclipse-compiler v2.7.0. The only new plugin that has been added since the app stopped working is a test code coverage plugin, cobertura-maven-plugin v2.6Robinson
R
22

ShortTypeHandling was introduced in groovy-all-2.3.0.jar so the quick fix was to replace the older groovy-all-x.x.x.jar with groovy-all-2.3.0.jar. This solved the runtime ShorTypeHandling ClassNotFoundException but also created new problems by introducing a new groovy-all.jar dependency in the application.

The real issue was how the groovy compiler was being invoked via maven. Because I introduced spock which required groovy 2.0, I needed to update the maven entries for the groovy-eclipse-compiler dependency. Here are the updated maven entries for working with groovy 2.x:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <!-- Java version -->
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.8.0-01</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-batch</artifactId>
                    <!-- Groovy version -->
                    <version>2.1.8-01</version>
                </dependency>
            </dependencies>
        </plugin>

With this in place, I could leave my groovy-all dependency the way I originally had it for the working/fully tested application like this:

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <!-- If possible, its better if this matches 2.1.8 in the plugin definition -->
        <!-- but 2.2.1 worked fine here and allowed me to keep the original pom definition  -->
        <version>2.2.1</version>
    </dependency>

The application runtime no longer references the ShortTypeHandling class and everything worked as it previously did.

Robinson answered 25/5, 2014 at 23:6 Comment(1)
You might find Guillaume's release announcement helpful: groovy.329449.n5.nabble.com/…. They introduced a compatibility jar to add this class.Africah
E
20

You have to add (If you are using Gradle)

compile 'org.codehaus.groovy:groovy-backports-compat23:2.4.5'
Esmond answered 28/8, 2014 at 6:50 Comment(0)
S
13

I've just had this after updating the groovy-eclipse Feature in Eclipse (in order to try and fix intermittent save issues caused by https://jira.codehaus.org/browse/GRECLIPSE-1519). Specifically in my case, my Groovy JUnit tests were throwing this exception.

In light of the suggestions above, I checked my Eclipse settings, and it was using Groovy 2.3.4.xx whereas my Maven POM was specifying 2.1.8.xx. I went to Window -> Preferences -> Groovy -> Compiler and clicked "Switch to 2.1.8.xx...", restarting Eclipse when prompted, and this fixed it.

Skimmia answered 15/8, 2014 at 13:40 Comment(1)
I struggled with this for a long time! Your post was the ticket. Thank you!Refluent
H
9

I've solved this issue by adding this dependency on my POM:

<dependency>
  <groupId>org.codehaus.groovy</groupId>
  <artifactId>groovy-backports-compat23</artifactId>
  <version>2.4.5</version>
</dependency>

Then, it works like a charm.

Headphone answered 17/10, 2014 at 10:5 Comment(0)
H
2

Matthew Wise's solution worked for me, but in addition to restarting eclipse, I also had to do a project -> clean for it to recompile with the new compiler.

(I would have commented on his answer, but stack overflow has this stupid rule that you can't comment until you get more reputation)

Hoicks answered 30/9, 2014 at 15:36 Comment(0)
J
1

I faced similar issue in our project. Surprisingly groovy version was not an issue. I was building the project with older version of gradle than the expected gradle version for the project. That resolved the error.

Jesuit answered 3/6, 2015 at 12:32 Comment(0)
I
0

Add following dependency to your pom.xml

     <dependency>
        <groupId>org.codehaus.groovy.maven.runtime</groupId>
        <artifactId>gmaven-runtime-default</artifactId>
        <version>1.0-rc-3</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Kuldeep Singh

Intension answered 21/9, 2014 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.