Creating a subproject with Buildship in eclipse

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.

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

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?

1 Like

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.

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.

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.

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

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

I face an issue here. While trying to run the main class from sub project, I get Error: Could not load or find Main class. Can any one help here?