如何在 Eclipse 中使用 Buildship 刷新项目依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31092934/
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
How do I refresh project dependencies using Buildship in Eclipse?
提问by Tagc
Eclipse Mars was recently released and I felt like trying it out. It listed tighter integration with Gradle as one of its features via Buildship.
Eclipse Mars 最近发布,我想尝试一下。它通过Buildship将与 Gradle 的更紧密集成列为其功能之一。
With Luna I was using Gradle Integration for Eclipse (4.4)and I found this a lot easier to work with for what I was trying to do; I could add a Gradle "nature" to an existing project without needing to remove the project and re-import it as I did with Buildship, and it automatically put all dependencies that I declared in build.gradle
within the project's classpath.
在 Luna 中,我使用Gradle Integration for Eclipse (4.4),我发现这对于我想要做的事情来说更容易使用;我可以向现有项目添加 Gradle“自然”,而无需像使用 Buildship 一样删除项目并重新导入它,它会自动将我声明的所有依赖项放入build.gradle
项目的类路径中。
With Buildship, I didn't see any option to configure an existing project as a Gradle project and I couldn't find a way to make it include the dependencies I specified in the build script within the project's classpath.
使用 Buildship,我没有看到任何将现有项目配置为 Gradle 项目的选项,而且我找不到一种方法让它包含我在项目类路径中的构建脚本中指定的依赖项。
I tried installing the original plugin (GIfE 4.4) for Eclipse Mars and after restarting Eclipse it automatically did all that for me again. What I'm wondering is if there's a way to do this all through Buildship alone because right now, although it all works, it's quite a funny setup. My project's dropdown menu looks like this:
我尝试为 Eclipse Mars 安装原始插件 (GIfE 4.4),在重新启动 Eclipse 后,它会自动再次为我完成所有这些操作。我想知道是否有一种方法可以单独通过 Buildship 来完成这一切,因为现在,尽管一切正常,但这是一个非常有趣的设置。我的项目的下拉菜单如下所示:
Apart from looking a bit odd it is actually quite a nice setup, since it combines the automatic dependency management of GIfE with the ability to run Gradle tasks directly from Eclipse that Buildship provides.
除了看起来有点奇怪之外,它实际上是一个很好的设置,因为它将 GIfE 的自动依赖项管理与 Buildship 提供的直接从 Eclipse 运行 Gradle 任务的能力相结合。
回答by Paul Adamson
Updating the dependencies that eclipse sees should then be as simple as:
更新 eclipse 看到的依赖项应该像这样简单:
right click on project -> gradle -> refresh all
Update in buildship 1.0.16
buildship 1.0.16 中的更新
Currently you need to jump through the delete-and-import hoop the first time you use an existing gradle project with buildship.You can now use the Add Gradle Nature option:
目前,当您第一次使用带有 buildship 的现有 gradle 项目时,您需要跳过删除和导入环节。您现在可以使用 Add Gradle Nature 选项:
right click on project -> configure -> Add Gradle Nature
“Refresh Gradle Project” is now also shown when right-clicking on any .gradle file as well as in the context menu of the Gradle editor. source
现在,右键单击任何 .gradle 文件以及 Gradle 编辑器的上下文菜单中也会显示“刷新 Gradle 项目”。来源
See update belowHowever sometimes you may find that when your project was imported, it didn't get the new Project and External Dependencies classpathentry which you would normally be able to see in your Project Properties -> Java Build Path -> Libraries
If this is indeed missing, add the following to your project's .classpath
file and all the gradle goodness should start working:
请参阅下面的更新但是有时您可能会发现,当您的项目被导入时,它没有获得您通常能够在您的项目中看到的新项目和外部依赖项类路径条目Project Properties -> Java Build Path -> Libraries
如果确实缺少,请将以下内容添加到您的项目的.classpath
文件和所有 gradle 优点应该开始工作:
<classpathentry exported="true" kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
Update in buildship 1.0.16
Gradle classpath container is restored if missing
When converting an existing Eclipse Java project to Gradle, the Gradle classpath container was missing. It is now always added when a project is a Java project.
buildship 1.0.16 中的更新
如果丢失,Gradle 类路径容器将被恢复
将现有 Eclipse Java 项目转换为 Gradle 时,缺少 Gradle 类路径容器。当项目是 Java 项目时,它现在总是被添加。
回答by robross0606
I agree Buildship is a bit of a disaster. The documentation is extremely sparse with limited examples and minimal user guide. You would think documenting the transition from Gradle Integration for Eclipse (4.4) would be a no-brainer but I guess not. I also don't have a single clue how to use Buildship other than that I ran some tasks manually and it put fully qualified pathsin my .classpath file. That's ridiculous considering many projects are shared through change control systems.
我同意 Buildship 有点灾难。文档极其稀少,示例有限,用户指南极少。您会认为记录从 Gradle Integration for Eclipse (4.4) 的转换是轻而易举的事,但我想不是。除了我手动运行一些任务并将完全限定的路径放入我的 .classpath 文件之外,我也没有任何线索如何使用 Buildship 。考虑到许多项目是通过变更控制系统共享的,这很荒谬。
回答by Chandru
Incase for anyone, if you are not getting the
以防万一,如果你没有得到
right click on project -> gradle
右键单击项目-> gradle
link after doing the steps mentioned in @PaulAdamson answer. Try this.
执行@PaulAdamson 回答中提到的步骤后链接。尝试这个。
- In your build.gradle add
apply plugin 'eclipse';
- Close the project in eclispe.
Run the gradle build from command line and then reopen the project in eclipse.
Now the gradle link should be available on right click.
- 在你的 build.gradle 添加
apply plugin 'eclipse';
- 关闭 eclispe 中的项目。
从命令行运行 gradle build,然后在 eclipse 中重新打开项目。
现在 gradle 链接应该在右键单击时可用。
回答by Donát Csikós
Currently there is no "Convert to Gradle project" implemented in Buildship. However, if you remove the project and reimport it using the Gradle import wizard you should see the same exact project with the proper nature and the classpath container.
目前在 Buildship 中没有实现“转换为 Gradle 项目”。但是,如果您删除项目并使用 Gradle 导入向导重新导入它,您应该会看到具有适当性质和类路径容器的完全相同的项目。
On top of that, if you have a Gradle project in your workspace and update the dependencies in the build script, you can refresh the classpath container by right-clicking on the project and select Gradle > Refresh projects
.
最重要的是,如果您的工作区中有一个 Gradle 项目并更新构建脚本中的依赖项,您可以通过右键单击该项目并选择 来刷新类路径容器Gradle > Refresh projects
。
A similar problem you were facing was discussed in the Gradle forums: discuss.gradle.org/t/adding-dependencies-to-projects/10415.
在 Gradle 论坛中讨论了您面临的类似问题:discuss.gradle.org/t/adding-dependencies-to-projects/10415。
We also have a bug dedicated for this feature request: bugs.eclipse.org/bugs/show_bug.cgi?id=465355. Please vote for it and share your thoughts there too.
我们还有一个专用于此功能请求的错误:bugs.eclipse.org/bugs/show_bug.cgi?id=465355。请投票支持并在那里分享您的想法。
Regarding to the documentation: It's true that we haven't provided an official documentation for the central Eclipse help system, but there are some resources explaining the current functionality:
关于文档:我们确实没有为中央 Eclipse 帮助系统提供官方文档,但有一些资源解释了当前的功能:
回答by user204069
If you have already converted Java project to Gradle project but [RIGHT-CLICK]+Import (Then importing 'Existing Gradle Project') then your project should be of Gradle Nature.
如果您已经将 Java 项目转换为 Gradle 项目,但 [RIGHT-CLICK]+Import(然后导入“现有 Gradle 项目”),那么您的项目应该属于 Gradle 性质。
If the project is of Gradle Nature then in .classpath file you will not see all the .jar dependencies as you see in normal java project, Instead you will see a single entry of:
如果项目属于 Gradle Nature,那么在 .classpath 文件中,您将不会像在普通 Java 项目中看到的那样看到所有 .jar 依赖项,而是会看到一个条目:
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
To refresh dependencies you should do following:
要刷新依赖项,您应该执行以下操作:
[RIGHT-CLICK] + Gradle + Refresh Gradle Project
[右键单击] + Gradle + 刷新 Gradle 项目
This will fix all complication issues.
这将解决所有复杂问题。