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.
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.
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.
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?
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!