2012-08-09

Gradle introspection

I've been using the Gradle build tool for a while now, and it has been a very good experience. Not so much with Groovy beyond scripts, but that is another story... :)

Today I had a dependency problem caused by two alternative libraries being loaded at the same time (see SLF4J Multiple Binding).

To diagnose the problem I used the following Gradle inspection commands:
gradle dependencies

gradle properties

gradle tasks
(see user guide, chapter 11)

Here the excerpt from the dependencies command:
------------------------------------------------------------
Project :Util
------------------------------------------------------------

compile - Classpath for compiling the main sources.
+--- junit:junit:4.10 [default]
|    \--- org.hamcrest:hamcrest-core:1.1 [compile,master,runtime]
+--- org.apache.jena:jena-core:2.7.2 [default]
|    +--- org.apache.jena:jena-iri:0.9.2 [compile,master,runtime]
|    |    +--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime]
|    |    +--- org.slf4j:slf4j-log4j12:1.6.4 [compile,master,runtime]
|    |    |    +--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime] (*)
|    |    |    \--- log4j:log4j:1.2.16 [compile,master,runtime]
|    |    \--- log4j:log4j:1.2.16 [compile,master,runtime] (*)
|    +--- xerces:xercesImpl:2.10.0 [compile,master,runtime]
|    |    \--- xml-apis:xml-apis:1.4.01 [compile,master,runtime]
|    +--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime] (*)
|    +--- org.slf4j:slf4j-log4j12:1.6.4 [compile,master,runtime] (*)
|    \--- log4j:log4j:1.2.16 [compile,master,runtime] (*)
\--- javax.mail:mail:1.4.5 [default]
     \--- javax.activation:activation:1.1 [compile,master,runtime]

...
(*) - dependencies omitted (listed previously)

To exclude the log4j binding dependency, I added the following to build.gradle:
configurations {
    all*.exclude(group: 'org.slf4j', module: 'slf4j-log4j12')
    all*.exclude(group: 'log4j', module: 'log4j')
}
(see user guide 43.4.7. Excluding transitive dependencies
)

The new dependency tree now excludes the troublesome dependency:
compile - Classpath for compiling the main sources.
+--- org.apache.jena:jena-core:2.7.2 [default]
|    +--- org.apache.jena:jena-iri:0.9.2 [compile,master,runtime]
|    |    \--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime]
|    +--- xerces:xercesImpl:2.10.0 [compile,master,runtime]
|    |    \--- xml-apis:xml-apis:1.4.01 [compile,master,runtime]
|    \--- org.slf4j:slf4j-api:1.6.4 [compile,master,runtime] (*)
\--- javax.mail:mail:1.4.5 [default]
     \--- javax.activation:activation:1.1 [compile,master,runtime]

...

No comments: