Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle add library to classpath

I am using Gradle for a project. My build.gradle has got JUnit as a dependency, but every time I import the project again it does not recognize the JUnit library and asks me to add it to classpath. This problem does not only apply to JUnit, but also to other dependencies. Did I add JUnit to the wrong place?

PS: The project builds just fine, it's just the IDE (IntelliJ) that's marking everything red.

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

Screenshot of the error

like image 690
El Mac Avatar asked Feb 16 '16 15:02

El Mac


People also ask

What is classpath in Gradle?

Gradle dependencies are grouped into sets called configurations. Different configurations are used for building classpath for the major two tasks — compile classpath is used for compilation and runtime classpath is used for running the application.


2 Answers

The dependency declaration is correct. Probably you're opening the project in IntelliJ IDEA the wrong way.

I suggest you to open a Gradle project this way:

  1. Click the File | Open menu
  2. Select the build.gradle file

Here is further information about importing Gradle projects (see also the side note in that page).

like image 56
Paolo Fulgoni Avatar answered Sep 22 '22 06:09

Paolo Fulgoni


download the external jar file from mvn repository and add it to libs folder.

  1. Gradle-project(your project)->libs(inside libs folder paste jar file). if you don't have libs folder just create it.

  2. go to build.gradle dependencies { compile files('libs/your_jar.jar') }

  3. reload the gradle project.

it's worked for me. i hope it's work for you guys also...

like image 25
Sivaprakash D Avatar answered Sep 20 '22 06:09

Sivaprakash D