/ Vaadin Flow Framework

Groovy and Kotlin with Vaadin 10

Yet again a month has passed since the latest release of the Gradle Vaadin Flow plugin and now it is time for the fifth release of the plugin. This release focuses on exciting alternative JVM languages, Groovy and Kotlin!

Building Vaadin applications with Groovy

The plugin now provides templates in Groovy for all the creation tasks the plugin has. To enable the Groovy support you will need to include the official Groovy plugin in your build.

To do that add the following:

plugins {
    id 'groovy'  
    id 'com.devsoap.vaadin-flow' version '1.0.0.M5'
}

vaadin.autoconfigure()

That is it, nothing more needed.

Note: If you are not using vaadin.autoconfigure() you will need to add the Groovy dependency to your compile classpath. Like this:

dependencies {
  compile vaadin.groovy()
}  

Once you have the Groovy plugin in the project all tasks the plugin has will generate Groovy instead of Java. To try it out you can try creating a new project with gradle vaadinCreateProject you will see the following structure:

├── src
│   └── main
│       ├── groovy
│       │   └── com
│       │       └── example
│       │           └── vaadinflowplugintest
│       │               ├── VaadinFlowPluginTestServlet.groovy
│       │               ├── VaadinFlowPluginTestUI.groovy
│       │               └── VaadinFlowPluginTestView.groovy
│       └── webapp
│           └── frontend
│               └── styles
│                   └── vaadinflowplugintest-theme.css

All the other create* tasks will also now generate Groovy instead of Java, go ahead and try them out!

Building Web Templates with Groovy

One special feature the Groovy support brings is allowing you to build your Web Templates with Groovy.

If you run gradle vaadinCreateWebTemplate you will now see a new template file generated into src/main/webapp/frontend/templates ending with .tpl instead of .html. If you look into it it will look like this:

link (rel:'import', href: '../bower_components/polymer/polymer-element.html')

'dom-module' ( id:'example-web-template') {
    template {
        div (id:'caption', 'on-click' : 'sayHello') {
            yield '[[caption]]'
        }
    }

    script('''
        class ExampleWebTemplate extends Polymer.Element {
            static get is() {
                return 'example-web-template'
            }
        }
        customElements.define(ExampleWebTemplate.is, ExampleWebTemplate);
    ''')
}          

The TPL file format is a DSL provided by the Groovy Markup Template Engine to allow you to define HTML files programmatically with Groovy. At build time these templates will automatically be converted into plain HTML files.

So why use them?

The DSL allows you to use any Groovy inside the templates, compose templates into each other, inject file system properties and everything you normally can do with Groovy. No more error prone manual editing of HTML files needed, the Groovy compiler will notify you of errors at compile time if your syntax is wrong, not at runtime in production.

The TPL support will for now only be available for Groovy projects, but in the future it might also be enabled for other project types.

Kotlin support

As well as Groovy support, also Kotlin support has been added to the plugin.

Similarly to how the Groovy support works, you need to include the official Kotlin plugin to enable the Kotlin features.

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.2.61'
    id 'com.devsoap.vaadin-flow' version '1.0.0.M5'
}

Once you have that in your build.gradle you can create a Kotlin project with vaadinCreateProject and you will get the same file structure as with the Groovy project.

The other tasks will also provide Kotlin templates.

If you are building your Vaadin applications with Kotlin I can also highly recommend looking into Vaadin On Kotlin maintained by Martin Vysny (https://github.com/mvysny).

--

As usual the release is available to download from the Gradle Plugin Directory.

For more information about how to use the plugin see https://github.com/devsoap/gradle-vaadin-flow/wiki

If you find any issues do not hesitate to create an issue at https://github.com/devsoap/gradle-vaadin-flow/issues