Installed Kepler-based STS 3.4.0.RELEASE (current latest version) and the Gradle Support package from the Dashboard Extensions. Now I would like to create a Spring MVC project from scratch that uses Gradle as its build and dependency management tool instead of Maven.
I start by creating a Spring Project with a Spring MVC Project Template, but apparently this is based on Maven, and there is no option in any wizard screen to switch the project to Gradle. So, after creation, I right-click on the project and select Configure > Convert to Gradle Project. However, contrary to my expectations, the project still holds its Maven nature, dependencies in the project still belong to Maven despite Gradle having dependency resolution enabled, the pom.xml
file is still there, and there is no build.gradle
file anywhere to be seen. Eclipse's Console reports a successful build, which I believe comes from Gradle: but based on what? When I open the Gradle Tasks view, it is empty; if I try to refresh it, a message saying that the model is not yet available appears, just before triggering another successful build. Then, when I try and remove the Maven nature from the project, errors start to appear, about classes and tag library descriptors that are not found anymore. I select Gradle > Refresh Dependencies from the contextual menu of the project, but it has no effect.
I try the other way around: create a Gradle project from scratch. Unfortunately, Gradle templates do not cover Spring projects at all, and adding the Spring nature afterwards has no tangible effect, nor I am able to find a way to apply the Spring MVC Project Template to this newly created Gradle project.
On the Internet, everyone talks about how powerful the import facility of the Gradle Eclipse plug-in is, and how to create a Gradle project outside the IDE, then create the necessary files for Eclipse to be able to import the project, finally import it and be able to develop using the IDE. The sample project used in these tutorials is not a Spring MVC project, so I would be left on my own as the creation of the directory hierarchy and further configuration are concerned.
So I wonder: is such a thing as creating a Spring MVC Project with Gradle from within STS even possible at this time? Given that STS, Spring, and the Eclipse Gradle plug-in are developed by the same vendor, you would bet it is, because it seems such a basic feature that would hardly be missing from even a first release of STS/Spring/Gradle integration tools. So, did I miss something when trying to achieve my goal? And, just in case this is not possible, are there any other means to create a Gradle-based Spring MVC project from within STS? Or just properly convert a Maven-based one to Gradle?
From STS, click on File => New => Project. Select Spring Starter Project as shown below and click next. In the next screen, enter the name of the application (DemoApp) and then select type as gradle (Buildship). Then you need to enter the various packaging parameters for your project.
Step 1: Open your Eclipse IDE and go to File » Import. Step 2: Search for Gradle, expand the folder and go to Gradle » Existing Gradle Project » Next. Step 3: Specify the root directory of the Gradle project to import and click on the Next button.
This question is old and there probably wasn't a good answer to your question when it was asked, but today there is.
You can import gradle-based versions of any of the spring.io getting started guides.
To import these projects most easily you will need a recent version of STS and Gradle Tooling (e.g. release 3.5.1). Then use the 'Import Getting Started Content' Wizard from the 'File >> New' menu. The wizard lets you search the available guides and import their sample projects configured either as maven or gradle projects.
@Giulio, you couldn't express better my thoughts on this.
I can link a partial solution here: Gradle – Spring MVC Web Project Example. Partial because the created project won't look as a Spring project inside STS, so I fear you will loose something.
I hope to see in STS an automated way to create a Spring project that uses Gradle as soon as possible. In the meanwhile I'll rely on Maven...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With