Dependency control


(Mohammed Muhad) #1

I need to exclude commons-logging and log4j from my project since we are using slf4j and logback.

I added the below code to the init.gradle and it worked fine.

configurations.all {
  all*.exclude group: 'commons-logging'
  all*.exclude group: 'log4j'
}

For one of the project , I had to use create jibx binding

configurations {
  bind
  bindGen
  }
dependencies {
   bind "org.jibx:jibx-bind:$jibxVersion"
   bindGen "org.jibx:jibx-tools:$jibxVersion"
      }

When I run the above project, I get NoClassDefFoundError

Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/Logger

I added the log4j classes to the bindgen configuration , but I still get the NoClassDefFoundError. If I remove the exclude in the configuration within init.gradle , then it works fine. But my final war will be having

the commons-logging and log4j which I want to avoid.

Does the exclude configuration in init.gradle force on configuration that we define within a project ( like bind , bindGen ) in the above example.

If yes , how do we specify the classpath only for bindGen , still retaining the exclude configuration in init.gradle ?


(Szczepan Faber) #2

The exclusions can be configured slightly simpler:

configurations.all {
        exclude group: 'commons-logging'
        exclude group: 'log4j'
}

When I run the above project, I get NoClassDefFoundError

What do you mean by ‘run the project’?

Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/Logger

Can you paste the stack track to gist and paste a link?


(Mohammed Muhad) #3

Thanks for the simpler syntax for exclusions.

What I mean by running the project is that I ran the command “gradle build” for the project.

When I run “gradle build” command , I get a class not found error

Below link has the stack trace

https://gist.github.com/4578800

But If I comment the exclusions , then the jibx tool is able to access the log4j classes


(René Groeschke) #4

everything you configure via

configurations.all {
....
}

is applied to EVERY configuration. Gradle does not differ between configurations that are introduced by plugins (e.g. compile, runtime, testruntime…) or your own added configurations. So you have to change your init.gradle file to get your createBinding service to work as expected:

configurations.findAll {!it.name.startsWith(bind')}.each { conf ->
   conf.exclude group: 'commons-logging'
   conf.exclude group: 'log4j'
}

Another workaround might be to use the log4j-over-slf4j.jar library in your bind* configurations.

hope that helped. cheers, René


(Mohammed Muhad) #5

Thanks . I tried the workaround by adding log4j to bing confiugrations.It works

Sorry :slight_smile: should have tried it myself before posting this…