Multi project builds

buildship
eclipse

(Dan Gravell) #1

I’m trying to work on a multi project build in Buildship, but I don’t understand how to get it working. I’m new to Gradle in general.

I have two projects - client and shared. client depends on shared.

In the root folder (my workspace folder) I have settings.gradle:

rootProject.name = 'workspace'

include 'client'
include 'shared'

build.gradle is fairly empty:

// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
}

Both projects have their own build.gradle. client's is:

// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    compile project(':shared')
}

I removed settings.gradle from the two projects because I thought you shouldn’t have this in a multi project build.

But I can no longer choose Refresh Gradle Project. I get:

(For Google’s benefit):

Provided Eclipse project is not the root project

I guess I’m missing something obvious? I want Buildship and Gradle to both work so I can run builds from the command line and have dependencies shown in Eclipse sourced from one place.


(Stefan Oehme) #2

I guess you imported them individually at the start? At that time they still had their own settings.gradle, so they were considered root projects themselves. But now you want them to be parts of another root project. In that case you’ll have to remove them from the workspace and import the root instead.

Cheers,
Stefan


(Dan Gravell) #3

Thanks. I’m not sure exactly what you mean by import here… and I’m not sure how the hierarchical nature of multi project builds fit into Eclipse’s flat project structure.

I imported these projects into Eclipse as plain Java projects, that’s true. At this stage they have no Gradle files.

Then I added the Gradle nature and ran gradle init on the projects. That’s when the settings.gradle files were added and the projects became usable by Buildship - at this stage I could add GAV dependencies and these were propogated into eclipse.

Then I created the root build and settings.gradle and removed settings.gradle from the child projects.

So it sounds like I’ve done this incorrectly.

So what I don’t understand is:

  • What do you mean by import here? Import into eclipse? Using which importer?
  • How does the hierarchical multi project structure fit into eclipse’s flat project structure - should the structure be:

->

workspace/
    root-build/
        shared/
        client/

Ideally I would just want root-build, shared and client as projects in Eclipse.


(Stefan Oehme) #4

You need to import (or refresh if it’s already imported) the root project. The configuration of the children will be corrected after that.


(Dan Gravell) #5

Sorry - I don’t understand. If I start over with a new workspace and import the root project into Eclipse I get one project in Eclipse. How do I make each of the child projects a Gradle and Java project in their own right?


(Stefan Oehme) #6

Did you actually include the subprojects in the root project’s settings.gradle?


(Dan Gravell) #7

They are there, yes. But I added them after initially setting up the child projects, and haven’t re-imported yet. I guess I’ll give that a go.


(Dan Gravell) #8

Ok, here’s what I tried.

I removed client and shared from eclipse. I deleted the projects from eclipse, leaving the files on the file system.

Then I did a Gradle import for the workspace folder. Note workspace is both the root of the Gradle build and the Eclipse workspace root. The import appeared to proceed, I clicked to keep the existing .project files. Both client and shared were imported, as well as workspace.

Now, when I tried to refresh the child projects I get a different error message, but pointing to the workspace instead:

A project with the name workspace already exists.

It sure does…

Then I tried something different. I moved workspace, client and shared to a different folder, not having workspace as being the eclipse workspace.

This time it appears to have worked, so thanks for putting me on the right track!


(Stefan Oehme) #9

That’s not supported by Eclipse. The workspace root can’t be a project itself.

Yep, that’s the way to go.