Search code examples
javagradlemockito

Installing Mockito using Gradle


I have installed Gradle by adding the path to it into the system variables. I am quite new to Java and this is the first time that I am trying to install an external library for it. On the Mockito web-page, they say that one can:

Declare a dependency on “mockito-core” library using your favorite build system. With Gradle one can do:

repositories { jcenter() }
dependencies { testCompile "org.mockito:mockito-core:1.+" }

So I have no idea what it means. I changed the directory in cmd to the Gradle folder and tried to execute these commands, but that is not how one is supposed to do it. Can you give me a hand here?


Solution

  • You have to create a build.gradle file where you can insert the dependency. I recommend using an ide like eclipse or IntelliJ which can generate a gradle project for you so you don't have to do this manually. Just install the corresponding Gradle Plugin. This also makes sure you have a correct project structure.