Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start with STS and Gradle

Tags:

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?

like image 840
Giulio Piancastelli Avatar asked Feb 01 '14 11:02

Giulio Piancastelli


People also ask

How do I run Gradle spring boot project in STS?

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.

How do I import and run a Gradle project in STS?

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.


2 Answers

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.

like image 123
Kris Avatar answered Nov 01 '22 16:11

Kris


@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...

like image 32
bluish Avatar answered Nov 01 '22 16:11

bluish