My project uses junit-4.8.2.jar and mockito-all-1.8.5.jar; both includes Hamcrest 1.1. This is working just开发者_如何学JAVA fine until I added hamcrest-all-1.2.jar; now I get various NoSuchMethodError, because apparently my code compiles to Hamcrest 1.2, but is being run with Hamcrest 1.1.
It looks like there are various ways to solve this problem (e.g. use junit-dep-4.8.2 instead, etc), but is there a way to tell Eclipse to prefer Hamcrest 1.2. at run-time as well as compile-time?
It was already mentioned in the comments, but i think it's also a valid answer: Use Maven to handle the dependency management. If you don't want to use Maven (because you already use Ant or anything like that), use Ivy, Gradle, Buildr or any other build tool with dependency management.
精彩评论