Gradle – Exclude commons-logging from Spring

Gradle example to exclude commons-logging from Spring frameworks.

build.gradle

    compile('org.springframework:spring-webmvc:4.2.4.RELEASE'){
        exclude group: 'commons-logging', module: 'commons-logging'
    }

If you have multiple Spring dependencies, you have to exclude for each

build.gradle

    compile('org.springframework:spring-webmvc:4.2.4.RELEASE'){
        exclude group: 'commons-logging', module: 'commons-logging'
    }

    compile('org.springframework:spring-test:4.2.4.RELEASE'){
        exclude group: 'commons-logging', module: 'commons-logging'
    }

A better solution is excluding commons-logging at the project level.

build.gradle

	configurations.all {
	    exclude group: "commons-logging", module: "commons-logging"
	}

    compile 'org.springframework:spring-webmvc:4.2.4.RELEASE'
    compile 'org.springframework:spring-test:4.2.4.RELEASE'

References

  1. Spring MVC + Logback SLF4j example
  2. Gradle – Display project dependency

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Jitendra PatelFabricio Zelada Recent comment authors
newest oldest most voted
Fabricio Zelada
Guest
Fabricio Zelada

Keeps telling me exclude is an unrecognized symbol. Using gradle 3.3

Jitendra Patel
Guest
Jitendra Patel

I also faced exact same issue and I was able to resolve the issue from here: https://discuss.gradle.org/t/you-cant-change-a-configuration-which-is-not-in-unresolved-state-when-building-for-sonar/4631

Update config as below:

configurations {
[compile, runtime]*.exclude module: “org.osgi.foundation”
}