maven - Eclipse: The type org.hamcrest.core.CombinableMatcher$CombinableBothMatcher cannot be resolved. It is indirectly referenced from required .class files -
i working on unit testing spring mvc
controller using testng
, mockito
. i've included hamcrest
library in maven dependencies shown below. missing here? error shows when use following 2 methods:
org.hamcrest.matchers.hassize; org.hamcrest.matchers.is;
the following dependencies:
<dependency> <groupid>org.testng</groupid> <artifactid>testng</artifactid> <version>6.9.4</version> <scope>test</scope> </dependency> <dependency> <groupid>org.mockito</groupid> <artifactid>mockito-core</artifactid> <version>1.10.8</version> <scope>test</scope> </dependency> <dependency> <groupid>org.hamcrest</groupid> <artifactid>hamcrest-library</artifactid> <version>1.3</version> <scope>test</scope> </dependency>
update 1:
the problem has been resolved changing hamcrest-library
hamcrest-all
.
<dependency> <groupid>org.hamcrest</groupid> <artifactid>hamcrest-all</artifactid> <version>1.3</version> <scope>test</scope> </dependency>
update 2:
as per suggested tunaki, better solution exclude transitive dependency hamcrest-core
mockito
library. final dependencies should follows:
<dependency> <groupid>org.mockito</groupid> <artifactid>mockito-core</artifactid> <version>1.10.8</version> <scope>test</scope> <exclusions> <exclusion> <groupid>org.hamcrest</groupid> <artifactid>hamcrest-core</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.hamcrest</groupid> <artifactid>hamcrest-library</artifactid> <version>1.3</version> <scope>test</scope> </dependency>
there dependency conflict in pom:
mockito-core
1.10.8 depends onhamcrest-core
1.1.hamcrest-library
1.3 depends onhamcrest-core
1.3.
maven resolves conflict selecting version 1.1 (it declared first , have equal path).
you getting error because hamcrest-library
1.3 references combinablematcher
class that did not exist in version 1.1 does exist in version 1.3.
if depend on hamcrest 1.3 specific features, need exclude hamcrest-core
transitive dependency mockito-core
(and hope hamcrest 1.3 backwards compatible 1.1). otherwise, remove hamcrest-library
, depend on hamcrest 1.1.
Comments
Post a Comment