Conflicting groovy versions when running jetty

We have an application built with groovy 2.2.2 that works fine in itself, but when we run it with gradle 2.1 using jettyRun we get an exception since jettyRun has already loaded the incompatible groovy 2.3.6 version before the application is loaded:

Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.3.6 and you are trying to load version 2.2.2
 at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$DefaultModuleListener.onModule(MetaClassRegistryImpl.java:509) ~[groovy-all-2.2.2.jar:2.3.6]
 at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:78) ~[groovy-all-2.2.2.jar:2.3.6]
 at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:72) ~[groovy-all-2.2.2.jar:2.3.6]
 at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:54) ~[groovy-all-2.2.2.jar:2.3.6]
 at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110) ~[groovy-all-2.2.2.jar:2.3.6]
 at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:71) ~[groovy-all-2.2.2.jar:2.3.6]
 at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:33) ~[groovy-all-2.2.2.jar:2.3.6]

Is there any workaround for this that allows us to use gradle 2.1?

The bundled Jetty plugin is very outdated and limited. Among other things, it can’t run apps in a separate process. I recommend to use the third-party Gretty plugin instead (http://plugins.gradle.org/plugin/org.akhikhl.gretty/1.1.6).

OK thanks will try it.

I believe this should have worked to remove our own groovy version from the class path.

Unfortunately it had a disastrous side effect of somehow destroying the class path so that some parts of spring no longer would load. I suspect that realizing the dependencies by invoking the minus operator somehow did it too early. Strange.

[jettyRun,jettyRunWar]*.doFirst {
    httpPort = 8220
       // Must not have our own groovy
on the class path since it's already loaded by gradle
    // and if it isn't exactly the same version, then we get
    // "GroovyRuntimeException: Conflicting module versions"
    final FileCollection currentClasspath = classpath
    final FileCollection classpathWithoutGroovy = currentClasspath.filter {
        File f -> !f.name.contains('groovy-all')
    }
    classpath = classpathWithoutGroovy
}

Turns out that the spring problems came from some esoteric change in how automatic string => class type conversion was handled in groovy 2.2.2 -> 2.3.6. The above code works fine.

It would save us all a lot of time if you put up a warning sign in the documentation and referred to gretty.

http://www.gradle.org/docs/current/userguide/jetty_plugin.html