在 Eclipse 中更新我的分级依赖关系

在我的 Eclipse 中我有一个简单的 gradle 项目。我更新 build.gradle 以包括一些 apache http jar..。

dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile 'org.apache.httpcomponents:httpclient:4.2.3'
compile "org.apache.httpcomponents:httpmime:4.2.3"
testCompile group: 'junit', name: 'junit', version: '4.+'
}

然而在我的代码中,我引用了一些 Apache HTTP 的东西:

The import org.apache.http cannot be resolved

关于如何让 Eclipse 看到 build.gradle 中的新依赖项,有什么建议吗?

我尝试做一个清洁,但是没有工作。我的渐变插件是:

  Gradle IDE    3.3.0.201307040643-RELEASE  org.springsource.ide.eclipse.gradle.feature.feature.group   GoPivotal, Inc.
146456 次浏览

You have to select "Refresh Dependencies" in the "Gradle" context menu that appears when you right-click the project in the Package Explorer.

Follow those steps to update Gradle project in Eclipse:

  1. First, please check you have include eclipse gradle plugin. apply plugin : 'eclipse'
  2. Then go to your project directory in Terminal. Type gradle clean and then gradle eclipse.
  3. Then go to project in eclipse and refresh the project (Go to Project Explorer, select root of the project and hit F5 to refresh, or right click and select refresh in context menu).

enter image description here

You have to make sure that "Dependency Management" is enabled. To do so, right click on the project name, go to the "Gradle" sub-menu and click on "Enable Dependency Management". Once you do that, Gradle should load all the dependencies for you.

Looking at the Eclipse plugin docs I found some useful tasks that rebuilt my classpath and updated the required dependencies.

  • First try gradle cleanEclipse to clean the Eclipse configuration completely. If this doesn;t work you may try more specific tasks:
    • gradle cleanEclipseProject to remove the .project file
    • gradle cleanEclipseClasspath to empty the project's classpath
  • Finally gradle eclipse to rebuild the Eclipse configuration

I tried all above options but was still getting error, in my case issue was I have not setup gradle installation directory in eclipse, following worked:

eclipse -> Window -> Preferences -> Gradle -> "Select Local Installation Directory"

Click on Browse button and provide path.

Even though question is answered, thought to share in case somebody else is facing similar issue.

Cheers !

In my case, I solved weird issues in Spring Tools Suite (essentially Eclipse) after I tried to upgrade Spring Boot and the changes didn't seem to be taking effect.

Right click on your project -> Gradle -> Refresh Gradle Project