Programmatically add Buildship nature to new eclipse project from an Eclipse Plugin


(Thearon Helgeson) #1

I have an Eclipse Plugin that has extended the org.eclipse.ui.newWizards Extension Point and includes a wizard that builds a new java project in the correct structure that we need it to for our project types.
During project creation, we add natures to the project and one of those natures was the STS Gradle nature, which worked fine and no additional work was needed to configure the project to be a ‘gradle project’. I tried to simply do the same thing with the new Buildship gradle nature and ran into problems. The Builder is added correctly to the .project file, but as soon as the project is created, I get an error saying that the .prefs file for the project is missing. Is there something else I need to do during project creation that can set up a default .prefs file for my project? And once that is completed, will there be anything else I need to account for?

Ideally, there would be something like the JavaCore.create() has that evaluates and creates an instance of the the Project with the necessary configuration. Does anything like this exist?

(Stefan Oehme) #2

Hi Thearon,

there is currently no public API to do this.

If you are okay with depending on an implementation detail, you can write the ‘org.eclipse.buildship.core.prefs’ yourself. Just use the “New Gradle Project” wizard and you’ll see the default values you need to put into that file for a single-module project.


(Thearon Helgeson) #3

Hey Stefan,

Thanks for the quick response. It would be great if something like this could be added a future release instead of having to re-implement a solution that you guys have already completed.

For now, If I implement the creation of that preferences file, do you know of any other ‘mandatory’ elements of the gradle project that Buildship requires? The project already contains a build.gradle file and a settings.gradle file that gets generated and was used when creating the Gradle STS project. I assume these should port directly over to working in a Buildship project. Can you think of anything I may have missed?

Thanks in advance for any help,

  • Thearon

(Stefan Oehme) #4

Hi Thearon,

Yes, we plan to add some public API like this to Buildship at some point.

No, the nature and settings should make it work.


(Thearon Helgeson) #5

Stefan - That is very helpful. Thanks for your input.