/ Vaadin Framework

Get started with the Vaadin Gradle Plugin (Part 2)

This is the second part of getting started with the Vaadin Gradle plugin. In the last part we looked how we can create a new project and get it ready for importing into eclipse. In this part we are going to start with configuring our eclipse so it is easy to work with the gradle project and import our previously made project.

Eclipse with plugins and servers

The first thing you will need is have Eclipse installed. You can get it from Eclipse Download site and follow the instructions for installing it. Make sure you download the Eclipse IDE for Java EE Developers though, or else the WTP functionality won't work without further configurations.

Once you have Eclipse installed it is time to install some plugins.

As a side note before we begin, all eclipse plugins I install here are optional and are just to make development easier. They are not required for working with Vaadin Gradle plugin in any way but will make your life so much easier.

The first one you will want is the Vaadin Eclipse Plugin. The Vaadin Gradle plugin will configure the project to automatically support the Vaadin Eclipse Plugin if it is available.

Next, to make it easier to manage the gradle files I usually recommend the Minimalist Gradle Editor. It is a very lightweight plugin that provides syntax highlighting for *.gradle files among other things.

Finally, you will want to grab the Gradle Integration for Eclipse provided by Pivotal. It will allow you to run Gradle tasks directly from eclipse without needing to drop to the console whenever you need to run a task. It will also provide us with a nice import wizard we can use to import our Gradle project with.

All theses plugins can be found in the Eclipse Marketplace located under the Help menu in Eclipse. Just type the plugin name in the search box and you should find them. You will most likely need to restart Eclipse after you have installed the plugins.

Now we are all setup when it comes to the plugins, lets next take a look at servers.

While the Vaadin Gradle Plugin provides the embedded Jetty server via the vaadinRun task, I usually find it more conveinient to use another server directly from eclipse via Eclipse's WTP platform. You can find the installed servers under the Servers tab as seen below.

No WTP Servers Installed

As you can see, by default there are no servers installed. Lets remedy that by installing Apache TomEE which is a great server to run Vaadin applications on.

First we need to download the server so head over to https://openejb.apache.org/downloads.html and grab the Web Profile version of the server. You can download the server either as a TAR or ZIP archive. Once your download is complete extract the contents somewhere onto you file system.

Next, in Eclipse's WTP Servers window shown above click the link and you will be presented with the New Server dialog. Since Apache TomEE is essentially Apache Tomcat 7 + some extra goodies, select Apache and Tomcat v7.0 Server. In the "Server name:" field you can name your server as "Apache TomEE (WebProfile)" if you wish.

Click next and you will be greeted by the following dialog:

New TomEE Server

Change the Name again to something a bit more descriptive and by selecting the Browse button navigate to where you previously extracted the server files. Once you have done that click Finish and you should see the newly created server in the WTP Servers section.

TomEE Server installed

And now we have everything we need to run the Vaadin project in eclipse. Lets next import the project.

Importing project and running it

I assume you still have the project available we made is the previous part. If not, go back and create a new one.

Now in Eclipse select File -> Import... and select the Gradle-folder and Gradle Project.

In the dialog window that opens select Browse and browse to the project you previously created. Once you have your project folder selected you must click the Build Model button in the upper right corner. It will read the eclipse project files we generated in Part 1 for the project and create a model of the project for eclipse.

Once the model is complete select the project by checking the checkbox left to the project name.

Now, one very important final step before we continue. We need to disable the dependency management provided by the Gradle Eclipse Integration plugin we previously installed. Why? Because it will try to read the build.gradle file and try to deduce the dependencies without relying on gradle itself for dependency resolution. The Vaadin Gradle Plugin doesn't support this kind of behaviour and if we leave it on the Vaadin dependencies provided by the plugin will not be found. When we uncheck the dependency resolution the eclipse integration will instead use Gradle itself for dependency resolution and everything will work out-of-the-box.

Here is what it should look like once you have built the model and have selected the project and unchecked the dependency management:

Import Gradle Project

Now all that remains is clicking Finish and the project will be added to your workspace. It can take a while for the project to get imported as Gradle will start downloading all the dependencies needed for running and developing Vaadin applications on Eclipse. Once it is ready you can see the project in the Project Explorer and browse the source files.

Take some time to look around, check what source files the plugin has created for you and open the build.gradle and it should be nicely syntax highlighted.

When you are ready exploring, lets run the project!

In the WTP Servers dialog right click on the TomEE server you created and select Add and Remove... from the context menu. You will see your project in the Available column so just click on the project and click the Add button. Finally click Finish. Now your project is ready to be run via WTP.

To run the server just right click on the server and select Debug from the context menu and off you go! The server will take a while to start and once it has started head over to http://localhost:8080/myproject and you will see your project live and well.

Now as an excercise if you want, open up the HelloGradle class while the server is still running and replace "Hello vaadin" with "Hello gradle". Refresh the web page in the browser.


In this part we looked at how we can get eclipse setup for Vaadin development and how we can import our Gradle project into Eclipse. We also configured a server we can run the project on so we don't have to use the console and the vaadinRun task. In the next part we are closer going to look at the different tasks the Vaadin Gradle Plugin provides and how we can leverage them. So stay tuned!