4

I have two gradle java projects imported into Eclipse, one being a dependency of the other. I would like for Eclipse to use the local dependency code, instead of the compiled dependency in the gradle cache folders, so I can modify and debug both projects simultaneously.

How do I force Eclipse to use a local dependency code?

p4x
  • 384
  • 1
  • 5
  • 16
  • Q: If you "right-click the build.gradle file > Gradle -> Refresh Dependencies", that will ensure that "local" and "gradle cache" are both in sync. Correct? – paulsm4 Nov 16 '20 at 21:41
  • I cannot find option "Gradle > Refresh Dependencies" right-clicking on build.gradle.kts. But wouldn't right click on project and "Gradle > Refresh Gradle Project" do that too? I've tried that after adding the local dependency to the build path of the parent project, yet it is still using the cached .jar. – p4x Nov 16 '20 at 21:52
  • OK, "Gradle > Refresh Gradle Project" for your version of Eclipse. The point is to *overwrite* cache by (re)building/(re)downloading the "correct" version. Plan B: nuke ".gradle/caches/*": https://stackoverflow.com/a/23029580/421195 – paulsm4 Nov 16 '20 at 22:50
  • Already tried that too. It just regenerates the cache. So far the closest thing I've got is in Configure Build Path "Sources" Tab, to add as "Link Sources" the src/main/java & src/main/resources of the dependency project. But that is not exactly what I want because the common dependencies versions between both projects differ a bit (and now produces compilation errors in the dependency). – p4x Nov 17 '20 at 00:05

2 Answers2

1

The feature you are referring to is known as Composite Builds:

Importing into the IDE

One of the most useful features of composite builds is IDE integration. By applying the idea or eclipse plugin to your build, it is possible to generate a single IDEA or Eclipse project that permits all builds in the composite to be developed together.

In addition to these Gradle plugins, recent versions of IntelliJ IDEA and Eclipse Buildship support direct import of a composite build.

Importing a composite build permits sources from separate Gradle builds to be easily developed together. For every included build, each sub-project is included as an IDEA Module or Eclipse Project. Source dependencies are configured, providing cross-build navigation and refactoring.

The most simple way of achieving this is to use includeBuild in your settings.gradle.

rootProject.name = 'my-composite'

includeBuild 'my-app'
includeBuild 'my-utils'

With that in place, there's no need to configure the build path manually in Eclipse.

thokuest
  • 5,800
  • 24
  • 36
0

Gosh this was a trivial one and it took me way too long to figure it out.

Solved the issue by creating a file named external-projects.properties in the root folder of the parent project with the relative or full path to the dependency project folder.

To be precise, for me the folders tree ends up like this:

git-folder/
|__parent-project/
   |__external-projects.properties
   |__build.gradle.kts
   |__rest (src/main, etc)
|__dependency-project/
   |__build.gradle.kts
   |__rest (src/main, etc)

And the contents of the external-projects.properties file:

dependency-project = ../dependency-project

The dependency project must also be in the build path of the parent project (done by "Right-Click project > Build Path > Configure Build Path" and adding it in the "Projects" tab).

After that, a "Right Click > Gradle > Refresh Gradle Project" did the trick.

p4x
  • 384
  • 1
  • 5
  • 16