Creating a subproject with Buildship in eclipse

(jfriedman) #1

Using the Buildship plugin to create a new gradle project in eclipse, it insists on creating a root project. Is there any way to get around this and create a sub-project from the start with Buildship? If not, what do you suggest as best practise for our developers when creating a new sub-project in eclipse? By subproject, I mean an eclipse project that is part of a multi-module build whose root is some other project.

Thank you.

(Stefan Oehme) #2

Creating subprojects is currently not supported. The simplest workaround is to:

  • create the folder in the root project
  • include it in settings.gradle
  • refresh the Gradle project

(Preetham G R) #4

Will creating subprojects for existing root projects or any subprojects be considered in future release?

Also Why the subprojects doesn’t show up in hierarchical order in eclipse?

(Stefan Oehme) #5

There is currently no plan for a “create subproject” feature.

You can switch the “Project Explorer” to “Hierarchical” view. The “Package Explorer” doesn’t support this unfortunately. This is not something Gradle can change, it’s part of the Eclipse Platform.

(Ken Taylor) #6

I don’t understand the “no plans” comment. There is a real need to use sub-projects, but we’ve been asking for that feature in Eclipse since Europa.

However, here are the steps to create sub-projects:

  1. In your root project:
    1. Create a sub-folder, named appropriately.
    2. Edit settings.gradle and “include” that folder as a sub-project.
    3. Do a Refresh Gradle Project.
  2. In the new sub-folder (project):
    1. Create a build.gradle file.
    2. Edit it and add “apply plugin: ‘eclipse’”.
    3. If you are creating a Java project, also add “apply plugin: ‘java’”.
    4. Save the file.
  3. In the Gradle Tasks view:
    1. Refresh the view (toolbar button).
    2. Run the “eclipse” task, under “ide”, on your sub-project.
  4. In the Pacakge Explorer
    1. Refresh the root project.
    2. This will move the sub-project to the root level (Eclipse limitation).
    3. This will also move the new project out of any working set that you had selected. So use the Assign Working Sets to fix it.
  5. In your sub-project:
    1. If it is a Java project, do a Refresh Gradle Project. This will add the “.classpath” file.

Try it out and let me know if I missed anything.

(Stefan Oehme) #7

There is no need to do 3 refreshes. Just add the project to the settings.gradle file and add a build file for it, then refresh the root project.

This is unnecessary. You never need to run gradle eclipse when working with Buildship.

It will already have been refreshed together with the root project, no need for this extra step.

(Janek) #8

do I even need to “apply plugin: ‘eclipse’”?

(Stefan Oehme) #9

Only if you want to make adjustments to the eclipse configuration. Buildship will automatically apply it if you didn’t otherwise.