3

I am using STS/Eclipse to work on several Gradle projects which I have loaded on my workspace.

Some projects have dependencies on other projects, so I often need to perform Gradle builds into jar files, followed by a Gradle -> Refresh Dependencies and build up my dependency tree. This works fine, although I have noticed that sometimes Gradle will attempt to refresh the dependencies for all the projects in my workspace (even projects which are completely unrelated).

Not only is it bothersome and time-consuming having to wait for gradle to refresh all projects, but it also makes it difficult to debug issues with conflicting dependencies in the cache: Sometimes I want to disable a specific dependency on project A, but it still gets loaded to cache because an unrelated project B also has that dependency.

Is there a way to make gradle refresh the dependencies only for the project(s) I select instead of everything on my workspace?

For reference, I'm using STS version 3.6.3.RELEASE on Eclipse Kepler SR2 (4.3.2) using plugin Gradle IDE 3.6.3.201411271013-RELEASE org.springsource.ide.eclipse.gradle.feature.feature.group

1
  • I just created two separate, unrelated gradle project and when I select one of these projects and right click, then select 'Refresh Dependencies' from the context menu only the selected project gets refreshed.
    – Kris
    Sep 9, 2015 at 16:00

2 Answers 2

1

Seems this is an issue with the Gradle plugin on STS after all. How I solved it:

  • Opened Window -> Preferences ; selected Gradle menu

  • Disabled "Remap Jars to maven projects" and "Remap Jars to Gradle Projects".

  • Applied changes.

Not sure if this is also related/necessary, but I also:

  • Opened External Tools Configurations menu (Right click on project, Run as -> External Tools Configurations).

  • Went to the "Refresh" tab and changed the "Refresh resources upon completition" option from "The entire workspace" to "The project containing the selected resource" and applied changes.

  • I had to manually change this option on each project in my workspace.

Now I can perform gradle builds and refresh dependencies only on the projects I select instead of all projects on my workspace. Though if the project I select includes dependent jar files with missing dependencies, those will also be downloaded to cache (which makes sense).

Found useful information about this issue here:

https://github.com/spring-projects/eclipse-integration-gradle/issues/57

1
  • Ah I see, yes, turning on 'remapping' of gradle dependencies means that IDE will need models for all projects in the workspace. So that explains why refreshing a single project builds models for all.
    – Kris
    Sep 9, 2015 at 16:11
0

In that case, you can go to the folder with command prompt and exec the command below

gradle build

If you want force gradle to download all libraries again, you can use --refresh-dependencies option

gradle build --refresh-dependencies

This is the copy from gradle manual.

The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts. A fresh resolve will be performed against all configured repositories, with dynamic versions recalculated, modules refreshed, and artifacts downloaded.

1
  • Thanks for your reply. However, doing a gradle build on STS (even without the --refresh dependencies) was still downloading dependencies for all projects in my workspace. I suppose you mean performing the gradle build outside eclipse, but it seems more bothersome having to switch out to another window every time I want to build something. Furthermore, STS was also refreshing all dependencies upon startup, so either way I needed a solution within eclipse. I have now posted the solution that worked for me.
    – Pdrit
    Sep 9, 2015 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.