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.
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?
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:
- In your root project:
- Create a sub-folder, named appropriately.
- Edit settings.gradle and “include” that folder as a sub-project.
- Do a Refresh Gradle Project.
- In the new sub-folder (project):
- Create a build.gradle file.
- Edit it and add “apply plugin: ‘eclipse’”.
- If you are creating a Java project, also add “apply plugin: ‘java’”.
- Save the file.
- In the Gradle Tasks view:
- Refresh the view (toolbar button).
- Run the “eclipse” task, under “ide”, on your sub-project.
- In the Pacakge Explorer
- Refresh the root project.
- This will move the sub-project to the root level (Eclipse limitation).
- 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.
- In your sub-project:
- 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?