Insane Programming Java ramblings and finds on the net

9Feb/101

Excluding a dependency throughout the POM a.k.a. “the version 99 fix”

Although I am a Maven fanatic, that doesn't mean I don't get mad because of some missing features in Maven. One of those is general exclusion of dependencies.

Most projects still use either log4j or commons-logging for their logging needs. While there is nothing wrong with that, I prefer SLF4J. SLF4J also has these really nice adapters for libraries that use those other logging frameworks so everything gets logged through it anyway. And here lies the problem. When you want to use these adapter classes, you need to exclude the real log4j and commons logging libraries. When you only have like 3 dependencies, that's not a big issue. If you have 50+, it is. So you're left with 2 choices:

  • Exclude log4j and commons logging from every dependency (you'll need to look at the POM to see which one it uses)
  • Use the somewhat ugly, but effective version 99-does-not-exist fix