Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The import org.springframework.data cannot be resolved in gradle

I refreshed my gradle project but it gives me error that " The import org.springframework.data cannot be resolved "

The following are some imports which it doesn't understands

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.ScriptOperations;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.script.ExecutableMongoScript;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;

There are more imports which it is unable to resolve.

Please give me any suggestion to resolve this issue.

Thanks in advance.

like image 521
CandleCoder Avatar asked Sep 03 '15 04:09

CandleCoder


People also ask

What is dependencymanagement in Gradle?

In most cases, a project relies on reusable functionality in the form of libraries or is broken up into individual components to compose a modularized system. Dependency management is a technique for declaring, resolving and using dependencies required by the project in an automated fashion.

Where does Gradle look for dependencies?

How does Gradle know where to find the files for external dependencies? Gradle looks for them in a repository. A repository is a collection of modules, organized by group , name and version .

Does Gradle automatically download dependencies?

One of the main tasks of Gradle is to help the management of code dependencies. When we perform compilation, it will automatically download the dependencies and store them in cache before the compilation.

What is transitive dependency in Gradle?

Transitive dependencyA variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.


2 Answers

At the top of your build.gradle I recommend that you add the eclipse and intellij plugins.

apply plugin: 'eclipse'
apply plugin: 'idea'

These plugins function to generate the .project and .classpath files that the eclipse IDE uses (it does the same for IntelliJ, but I don't really know what those files are; *.iml maybe?).

Then from the command line you just do...

gradle eclipse

...and it figures out the dependencies, pulls the JARs over, and generates the .classpath and .project. If you have eclipse open while you are doing this, refresh the project and Voila. Every time you add a dependency in the build.gradle you do this workflow again. It works like a champ for me.

There is probably some Eclipse plugin to allow you to just do this whole thing from within the IDE. I've been doing it from the commandline for a while now because its just simple.

like image 95
Bob Kuhar Avatar answered Sep 23 '22 07:09

Bob Kuhar


Added a dependency into build.gradle file as :

org.springframework.data:spring-data-mongodb:1.7.2.RELEASE

This solved my problem.

like image 20
CandleCoder Avatar answered Sep 21 '22 07:09

CandleCoder