Do I really have to exclude asm:asm for every dependency that uses it transitively?


(Evan Cowden) #1

Unless I add exclusions for asm, my tests always fail with:

“java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.MethodVisitor, but class was expected”

From other posts, it seems that the conflict is between older versions of asm and the newer 4.0 version used by Gradle 1.2. I have to add exclusions to each of my dependencies that themselves have a dependency on asm < 4.0. If I remove the exclusions in the file below, I get the errors; it works as is.

Am I doing something wrong? Can I get isolation between the Gradle classpath and my project’s classpath?

— My build.gradle -----------------

apply plugin: ‘groovy’ apply plugin: ‘war’ apply plugin: ‘jetty’

repositories {

mavenCentral() }

dependencies {

groovy ‘org.codehaus.groovy:groovy:2.0.5’

testCompile ‘junit:junit:4.10’

compile “com.google.inject:guice:3.0” exclude group: ‘asm’, module: ‘asm’

compile “com.google.guava:guava:13.0.1”

compile “com.sun.jersey:jersey-core:1.14”

compile “com.sun.jersey:jersey-server:1.14” exclude group: ‘asm’, module: ‘asm’

compile “com.sun.jersey:jersey-servlet:1.14”

compile “com.sun.jersey:jersey-json:1.14”

compile “com.sun.jersey.contribs:jersey-guice:1.14” exclude group: ‘asm’, module: ‘asm’

compile “javax.servlet:javax.servlet-api:3.0.1” }

— My test case: ------------------ import org.junit.Test

import static org.junit.Assert.* import static org.hamcrest.CoreMatchers.*

class SimpleTest {

@Test

public void testSomething() {

assertThat 1, is(1)

} } -------------------------------------------


(Eric Berry) #2

From the build file above (without the exclusions) it appears that the asm 4.0 dependency is actually coming from Groovy not gradle (using ‘gradle dependencies’):

\--- org.codehaus.groovy:groovy:2.0.5
     +--- antlr:antlr:2.7.7
     +--- org.ow2.asm:asm-tree:4.0
     |
  \--- org.ow2.asm:asm:4.0
     +--- org.ow2.asm:asm-commons:4.0
     |
  \--- org.ow2.asm:asm-tree:4.0 (*)
     +--- org.ow2.asm:asm:4.0 (*)
     +--- org.ow2.asm:asm-util:4.0
     |
  \--- org.ow2.asm:asm-tree:4.0 (*)
     \--- org.ow2.asm:asm-analysis:4.0
          \--- org.ow2.asm:asm-tree:4.0 (*)

That being said, I was actually able to get your build to work by explicitly including the asm 4.0 dependency.

compile "org.ow2.asm:asm:4.0"

I believe that overrides the transitive dependencies.

I also tried it as a ‘runtime’ dependency which I believe works like maven’s ‘provided’ scope.


(Luke Daley) #3

You should use ‘groovy-all’ instead of ‘groovy’ because it bundles its dependencies internally, shaded.


(Evan Cowden) #4

Ah ha! Depending on groovy-all resolves the issue. Thanks for jumping in!

I’d like to update the documentation for the Groovy plugin (http://gradle.org/docs/current/userguide/groovy_plugin.html) so that the next guy doesn’t have this same issue. I’ve checked the contribution page (http://gradle.org/contribute), development page (http://gradle.org/development) and GitHub project (https://github.com/gradle), but I can’t find the documentation. Can you point me in the right direction?


(Luke Daley) #5

Great.

The file to update is here: https://github.com/gradle/gradle/blob/master/subprojects/docs/src/docs/userguide/groovyPlugin.xml

You can generate the userguide by running: ‘./gradlew userguideHtml’ (from the project root)

The generated files are at: ‘subprojects/docs/build/docs/userguide/index.html’