java 导入 org.springframework.data 无法在 gradle 中解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32366835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:05:39  来源:igfitidea点击:

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

javaspringspring-datarest-assured

提问by CandleCoder

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

我刷新了我的 gradle 项目,但它给了我一个错误“导入 org.springframework.data 无法解析”

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.

提前致谢。

采纳答案by CandleCoder

Added a dependency into build.gradlefile as :

build.gradle文件中添加了一个依赖

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

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

This solved my problem.

这解决了我的问题。

回答by Bob Kuhar

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

在 build.gradle 的顶部,我建议您添加 eclipse 和 intellij 插件。

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?).

这些插件的功能是生成 Eclipse IDE 使用的 .project 和 .classpath 文件(它对 IntelliJ 也是如此,但我真的不知道这些文件是什么;也许是 *.iml?)。

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.

...它找出依赖关系,将 JAR 拉过来,并生成 .classpath 和 .project。如果您在执行此操作时打开了 eclipse,请刷新项目并瞧瞧。每次在 build.gradle 中添加依赖项时,您都会再次执行此工作流程。它对我来说就像一个冠军。

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.

可能有一些 Eclipse 插件可以让您在 IDE 中完成这一切。我已经从命令行执行了一段时间,因为它很简单。

回答by Kyle Olson

I ran into a similar spring dependency problem, only in the Eclipse environment, and the answer wasn't a programming issue, it was just that Eclipse was failing to handle changes to the build.gradle file.

我遇到了类似的 spring 依赖问题,只是在 Eclipse 环境中,答案不是编程问题,只是 Eclipse 无法处理对 build.gradle 文件的更改。

If you can build your project successfully from the command line, you should trying closing Eclipse and restarting it. This solved my problem.

如果您可以从命令行成功构建您的项目,您应该尝试关闭 Eclipse 并重新启动它。这解决了我的问题。