vaadin / vaadin-gradle-plugin

Gradle plugin for Vaadin 14 applications. Takes care of front-end build, helps to configure repositories and to create various project and file templates.
Apache License 2.0
31 stars 9 forks source link
vaadin vaadin-gradle-plugin

Vaadin 14 Gradle Plugin

This is an unofficial Vaadin Gradle Plugin supporting Vaadin 14 only.

Official VS Unofficial Vaadin Gradle Plugins

There are two Vaadin Gradle Plugins:

This plugin only supports Vaadin 14. This plugin is developed by Vaadin employees, but it is only offered as a gesture of good will - it's not an official Vaadin offering. Official Vaadin Gradle plugin only works for Vaadin 19+ and is part of the Vaadin Flow Github repo.

Note that both this plugin and the official Vaadin Gradle Plugin are deployed to the same plugin space: com.vaadin at plugins.gradle.org. The unofficial plugin version numbering starts with a zero: 0.*.

Official Plugin (not this one)

More links for the official Vaadin Gradle plugin:

Features

Compared to Maven plugin, there are the following limitations:

Prerequisites:

As opposed to the older version of Gradle plugin, the new plugin doesn't create projects any more. We plan to support Gradle projects via start.vaadin.com at some point. In the meantime, refer to project examples that you can use as a basis for your Vaadin modules.

Getting Started

Please see the Vaadin 14 documentation: Starting a Gradle Project for more details.

Check out the example project setups for basic WAR project and Spring Boot:

To include the plugin in your project, simply add the plugin into the plugins{} section of your build.gradle:

plugins {
    id 'com.vaadin' version '0.14.8.1'
}

Compatibility chart:

Vaadin Gradle Plugin version Supports
- Vaadin 13 and lower are unsupported
0.6.0 and lower Vaadin 14.1.x and lower
0.7.0 Vaadin 14.2.x
0.8.0 Vaadin 14.3.x and higher
0.14.3.7 Vaadin 14.3.x and higher
0.14.5.1 Vaadin 14.5.x and higher
0.14.6.0 Vaadin 14.6.x and higher
0.14.7.3 Vaadin 14.7.0 and higher
0.14.7.5 Vaadin 14.7.5 and higher
0.14.8.1 Vaadin 14.8.0 and higher
- Vaadin 15 and higher are unsupported by this unofficial plugin

Tasks

There are the following tasks:

Most common commands for all projects:

Note (after you built the project in production mode): In order to prepare the project setup back to development mode, you must run ./gradlew vaadinPrepareFrontend with the productionMode effectively set to false (e.g. by ommitting the -Pvaadin.productionMode flag).

Configuration

To configure the plugin, you can use the following snippet in your build.gradle file:

build.gradle in Groovy:

vaadin {
  pnpmEnable = false // false is the default, this is just an example
}

All configuration options follow. With the exception of the productionMode setting, all other settings are auto-configured by the Plugin with sensible defaults and should not be changed, otherwise weird JavaScript toolchain-related bugs might occur:

Filtering classpath

The filterClasspath closure allows you to filter out Vaadin components to speed up the classpath scanning and the JavaScript build process (since 0.14.7.5). For example:

vaadin {
  filterClasspath {
//    include("com.vaadin:*")
    exclude("com.foo:bar-*")
  }
}

Note that the com.vaadin:flow-server is always included and can not be excluded, since it introduces vital interfaces and annotations.

In order to see the exact list of artifacts to be scanned, run Gradle with the --info parameter, then search for the Passing this classpath to NodeTasks.Builder string in the log.

See Issue 120 for more details.

Automatic Download of node.js and npm/pnpm

Since Vaadin Gradle Plugin 0.7.0, you no longer need to have node.js nor npm installed in your system in order to use Vaadin. Vaadin will download the node.js and npm (and pnpm if pnpmEnable is true) and will place it into the $HOME/.vaadin folder.

This functionality is triggered automatically, you do not need to call a Gradle task nor configure your CI environment in a special way.

Multi-project builds

It is important to apply this plugin only to projects building the final war/jar artifact. You can achieve that by having the com.vaadin plugin in the plugins{} block not applied by default, then applying the plugin only in the war project:

plugins {
  id 'java'
  id "com.vaadin" version "0.8.0" apply false
}

project("lib") {
  apply plugin: 'java'
}
project("web") {
  apply plugin: 'war'
  apply plugin: "com.vaadin"
  dependencies {
    compile project(':lib')
  }
}

IDE Support

Intellij support for projects using Gradle and Vaadin Gradle Plugin is excellent.

There's a known issue with Eclipse and VSCode. Eclipse+BuildShip may need a workaround in order for Gradle projects to work, please see https://vaadin.com/forum/thread/18241436 for more info. This applies to Visual Studio Code (VSCode) as well since it also uses Eclipse bits and BuildShip underneath - see https://github.com/mvysny/vaadin14-embedded-jetty-gradle/issues/4 for more details.

Developing The Plugin

See CONTRIBUTING for instructions for getting the plugin sources, and for compiling and using the plugin locally.

License

This plugin is distributed under the Apache License 2.0 license. For more information about the license see the LICENSE file.