9 April 2016

How to solve problem java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V gradle ?

PROBLEM:

When I practised TDD  I used added all libs manually(simply ask IntelliJ to take care of) , but I decided use gradle.I added  hamcrest ,junit (and Mockito ) and when I run gradle refresh ... I saw this:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
I couldn't figure out for a little bit why this happen and then I tried change order of  dependencies and that solved problem (I remembered ,I had similar problem in the past in other project).

SOLUTION:

Make sure  you put hamcrest dependencies before junit

dependencies {

    (...)   
    compile 'org.hamcrest:hamcrest-all:1.3'

    compile 'junit:junit:4.12'
    (...)

}

Done! Have an epic day/night fellow developer!