An Eclipse Vert.x Gradle Plugin
Eclipse Vert.x is a versatile toolkit, and as such it does not have any strong opinion on the tools that you should be using.
Gradle is a popular build tool in the JVM ecosystem, and it is quite easy to use for building Vert.x project as show in one of the vertx-examples
samples where a so-called fat Jar is being produced.
The new Vert.x Gradle plugin offers an opinionated plugin for building Vert.x applications with Gradle.
It automatically applies the following plugins:
java
(and sets the source compatibility to Java 8),application
+shadow
to generate fat Jars with all dependencies bundled,nebula-dependency-recommender-plugin
so that you can omit versions from modules from the the Vert.x stack.
The plugin automatically adds io.vertx:vertx-core
as a compile
dependency, so you don’t need to do it.
The plugin provides a vertxRun
task that can take advantage of the Vert.x auto-reloading capabilities, so you can just run it then have your code being automatically compiled and reloaded as you make changes.
Getting started
A minimal build.gradle
looks like:
Provided sample.App
is a Vert.x verticle, then:
gradle shadowJar
builds an executable Jar with all dependencies:java -jar build/libs/simple-project-fat.jar
, andgradle vertxRun
starts the application and automatically recompiles (gradle classes
) and reloads the code when any file undersrc/
is being added, modified or deleted.
Using with Kotlin (or Groovy, or…)
The plugin integrates well with plugins that add configurations and tasks triggered by the classes
task.
Here is how to use the plugin with Kotlin (replace the version numbers with the latest ones…):
Using with WebPack (or any other custom task)
WebPack is popular to bundle web assets, and there is even a guide for its integration with Gradle.
Mixing the Vert.x Gradle plugin with WebPack is very simple, especially in combination with the com.moowork.node
plugin that integrates Node into Gradle.
Suppose we want to mix Vert.x code and JavaScript with Gradle and WebPack.
We assume a package.json
as:
and webpack.config.js
as:
The build.gradle
file is the following:
This custom build exposes a webpack
task that invokes WebPack, with proper file tracking so that Gradle knows when the task is up-to-date or not.
The Node plugin adds many tasks, and integrates fine with npm
or yarn
, so fetching all NPM dependencies is done by calling ./gradlew yarn
.
The vertxRun
task now redeploys on modifications to files in src/
(and sub-folders), build.gradle
and yarn.lock
, calling both the classes
and webpack
tasks.
Summary
The Vert.x Gradle plugin provides lots of defaults to configure a Gradle project for Vert.x applications, producing fat Jars and offering a running task with automatic redeployment. The plugin also integrates well with other plugins and external tools for which a Gradle task is available.
The project is still in its early stages and we are looking forward to hearing from you!