Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse not recognizing Gradle dependencies

I am new to Gradle and I was trying this tutorial https://spring.io/guides/gs/rest-service/ I was able to compile the jar with the required dependencies and run it. However, I find it annoying that the libraries are not recognized by the IDE.

enter image description here

Is there anyway to do it?

like image 285
cvguy Avatar asked Jul 03 '16 15:07

cvguy


People also ask

How do I import Gradle dependencies into Eclipse?

Import an existing Gradle project You can also import existing Gradle projects into Eclipse. Select the File Import… ​ Gradle Gradle Project menu entry for this. After pressing the Next > button, you need to specify the root directory of your Gradle project.

How do I force a Gradle project to update in Eclipse?

When modifying the build configuration, you can apply the changes by executing the Gradle > Refresh Gradle Project command from the context menu of the project node or the build script editor. Project synchronization even respects the customizations done in Gradle eclipse plugin configuration.

How do I refresh Gradle dependencies in STS?

How do I refresh Gradle dependencies in STS? The Best Answer is. You have to select "Refresh Dependencies" in the "Gradle" context menu that appears when you right-click the project in the Package Explorer.

How do I set the Gradle home directory in Eclipse?

It is important to add the GRADLE_USER_HOME variable in Eclipse: Window->Preferences->Java->Build Path->Classpath Variable. Set it to the path of the ~/. gradle folder in your home directory (e.g. /home/<user_name>/. gradle/ (Unix) or C:\Users\<user_name>\.


2 Answers

You should use the gradle eclipse plugin. Add this to your build.gradle file:

apply plugin: "eclipse" 

This will add eclipse related tasks to your build. By executing

gradlew cleanEclipse eclipse 

Gradle will regenerate all eclipse project and classpath files based on the current dependencies of your project(s). You will however need to refresh your IDE to make the changes visible.

There is one more thing to consider. As eclipse is not really aware of the gradle dependencies - it knows them only by the generated classpath files - new dependencies will be visible to eclipse only after regenerating these files. Furthermore dependencies added in eclipse will not be visible to your gradle build and will be removed once the classpath files are regenerated.

like image 83
dpr Avatar answered Sep 30 '22 03:09

dpr


What worked for me is :

right-click the build.gradle file -> Gradle -> Refresh Dependencies.

like image 40
nanosoft Avatar answered Sep 30 '22 05:09

nanosoft