We have an Eclipse plugin that allows for creating Java projects using Gradle. We used the Gradle STS (Gradle IDE Pack) plugin to create a Gradle Java project in the past, but the Gradle STS plugin is no longer working in the latest Eclipse. So we are planning to use Gradle Buildship but when we are trying to add Gradle nature(org.eclipse.buildship.core.gradleprojectnature) to our Eclipse plugin code, it is giving below error while creating a Java project.
Also in eclipse .metadata/.log file, showing below error :
org.eclipse.buildship.core.internal.GradlePluginsRuntimeException: Can’t read root project location for project located at D:\Project\TestNewProject\TestThingworxProject
Can you first delete all .classpath and .projects files and all .settings folders of your root project and any sub-projects? Then import your project again: File > Import: Gradle > Existing Gradle Project
After that, look at the [Gradle Operations] Console in the Console View if there are any errors:
Or you could start with a minimal project generated with the Build Init Plugin and add missing pieces step by step. After a change you should refresh your project (right click on project: Gradle > Refresh Gradle Project) and check the console again.
I think our use case is not clear. We have our own eclipse plugin using which users can create Gradle projects. Here we do not want any manual actions for the users once the project is created. It should have all the dependencies without any need to refresh. See screenshot below for creating a new project using our plugin :
Here we are trying to use the Gradle BuildShip nature (org.eclipse.buildship.core.gradleprojectnature) in our custom Eclipse plugin code (Since the older Gradle STS plugin is no more found in eclipse marketplace). But when we generate Gradle based Java project then it shows Missing Gradle project configuration file: .settings/org.eclipse.buildship.core.prefs error.
We are looking for the way about adding the Gradle BuildShip nature in the plugin code. Please provide any references to the API or any other useful documentation that will help us resolve this issue.
@ oleosterhagen I have tried the solution you gave, but when we synchronize the build( build.synchronize(monitor)), it is giving the following warning and not able to synchronize project properly. I found this warning while debugging in this code CompatibilityChecker class (line no 55). Basically, it’s throwing an GradleConnectionException exception to that line.
Status WARNING: org.eclipse.buildship.core code=3 Project synchronization failed due to an error connecting to the Gradle build. org.gradle.tooling.GradleConnectionException: Could not fetch model of type 'BuildEnvironment' using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-8.1.1-bin.zip'.
If I manually use Gradle → Refresh Gradle Project after creating the project, it will sync the project properly without any warnings or exceptions in that line. So Is there anything I need to add to my custom Eclipse project or any other way to resolve this issue?
Are there no errors shown in the above mentioned places: Gradle Operations Console, Error Log, Console View?
Without sharing a small example it is difficult to help. Have you tried importing a minimal Gradle Build created by the Build Init Plugin with your custom Eclipse plugin?
@oleosterhagen I missed to notify you that I have resolved this issue. Actually, the main exception was coming as org.eclipse.swt.SWTException: Invalid thread access because this exception the above mentioned warning was coming. Basically this exception coming when listener code is called from outside the SWT Display thread. After investigating, I found that I forgot to add SubProgressMonitor and beginTask before gradle import logic in our custom eclipse plugin. After adding that code, the gradle project created and synced properly without any issues through our eclipse plugin.