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.
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.
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 .
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.
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.
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.
Added a dependency into build.gradle file as :
org.springframework.data:spring-data-mongodb:1.7.2.RELEASE
This solved my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With