Loading a Multi-Project Gradle Application in Eclipse

In our last episode we covered configuring Eclipse Mars to support Spring and Gradle development. In this post we’ll walk through the process of loading NixMash Spring into Eclipse for the first time. NixMash Spring is a multi-project app built exclusively in IntelliJ IDEA, so we’ll see what issues come up.

As you might have seen in the previous post, here is NixMash Spring in the Eclipse Project Explorer. We are ready to rock in Eclipse Mars. The “nixmash-spring” Workset contains the three Eclipse projects which comprise NixMash Spring, jpa, mvc, and the root Gradle application, nixmash-spring. The directory hierarchy will remain the same as in IntelliJ and GitHub, with a root folder, jpa and mvc under it.

Another important point to remember is that jpa and mvc are modules in IntelliJ IDEA, yet we can import them as bona fide Eclipse projects which is pretty awesome. And as I mentioned, although we have a “nixmash-spring” project in Eclipse we didn’t have in IntelliJ, the end result on GitHub and in the project directory tree will be exactly the same.

Before we kick things off, another good source on loading Spring Gradle projects into Eclipse is the Gradle STS Support Tutorial. Much of this process is also explained on that Spring.io Tutorial.

Get from GitHub

We’re going to clone NixMash Spring from GitHub to a subdirectory in our Eclipse Workspace. Yeah, the app was originally named Spring-Data and so to not screw up hundreds of links to the GitHub app I never changed it. We’ll do that here. You can, of course, rename it to anything you want.

Import Gradle Project into Eclipse

If you read the STS Tutorial it does a great job walking through all of the import steps and makes a point of loading the subprojects first. The STS tutorial is using the Pivotal Gradle Plugin. We’ll be using the Buildship Gradle Plugin for Eclipse from Gradleware instead (shown below), so our process will be slightly different.

With the Buildship Gradle Plugin we can import the entire multi-project NixMash Spring app at one time.

Building in Gradle

Our project is looking good in the Project Explorer. We’ve got this great Gradle Task View, so this is going to be great!

Let’s build our project in Gradle.

D’OH! The old “Could not find tools.jar” error! Seems Gradle needs to point to a JDK as its JAVA_HOME setting rather than a JRE as one might expect. To fix this we added a property to our gradle.properties file and for good measure added a local.properties file with the setting as well.

// Location of local JDK

Refresh Gradle Files

Here’s a handy service in Eclipse you’ll want to know about, Gradle – Refresh Project.

Besides “Refresh Gradle Project” it’s also helpful to know about the GUI configuration support for the Buildship Gradle Plugin. There is no Eclipse – Preferences configuration GUI. This is “by design” according to Gradleware. The Gradle Plugin from Pivotal does have a Preferences GUI tool, and it’s nice. The good news if using the Buildship Plugin is that all of your Gradle GUI config needs can be met in the Eclipse Run Configuration dialogs.

Alrighty then! We covered configuring Eclipse for Spring and Gradle and have imported our Multi-Project Spring Gradle app into Eclipse. Time to get back to coding!