When I run my unit tests, I get complaints from the test run phase of my build that there's a duplicate class in my classpath. I did not recently change my dependencies, so this is surprising.
[junit] Exception in thread "Thread-4" java.lang.LinkageError: loader (instance of org/powermock/core/classloader/MockClassLoader): attempted duplicate class definition for name: "org/apache/log4j/pattern/Log4j1MdcPatternConverter"
The class in question changes when I try using the @PowerMockIgnore
annotation to exclude that pattern, for example, if I do this:
@PowerMockIgnore({"org.apache.log4j.pattern.Log4j1MdcPatternConverter"})
It just complains about another class that's duplicated like Log4j1XmlLayout or Log4j1NdcPatternConverter. I can probably brute force which ones to exclude, but has anyone seen this problem before who knows the exclude pattern to use? The format I'd use is similar to this question about LinkageErrors in unit tests but for different classes.
Some other questions and answers have mentioned that they changed the order for their dependencies with log4j and other Apache related packages; in this situation I cannot change the load order of the dependencies because I don't control them in the build environment (I.E. I cannot change something in Maven or Gradle). I'm looking for the smallest change possible, and that should be just placing a PowerMockIgnore annotation at the top of the test class that's failing.