Vert.x Gradle Plugin
What the plugin does
This plugin simplifies building and running Vert.x applications with Gradle.
It automatically applies the following plugins:
-
application
+distribution
for packaging the app for the JVM -
shadow
to generate uber Jars with all dependencies bundled
You can omit versions from elements in the https://github.com/vert-x3/vertx-stack[the Vert.x stack as the plugin references the corresponding Maven BOM.
Note
|
From version 0.9.0 the plugin no longer sets the sourceCompatibility to Java 8. You can set it manually like in other Java projects .
|
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 you code being automatically compiled and reloaded as you make changes.
Note
|
If you encounter issues with your application still being running in the background due to how the Gradle caching works, then you may try running the vertxRun task with gradle --no-daemon vertxRun .
|
The plugin provides a vertxDebug
task enabling to debug your code.
Note
|
Reloading is disabled while debugging. Moreover in order to prevent warnings while in debug mode, Vert.x options maxEventLoopExecuteTime and maxWorkerExecuteTime are set to java.lang.Long.MAX_VALUE
|
Minimal example
plugins {
id 'io.vertx.vertx-plugin' version 'x.y.z' // (1)
}
repositories {
jcenter()
}
vertx {
mainVerticle = 'sample.App'
}
Replace x.y.z
with a version available on the Gradle Plugin Portal
Provided sample.App
is a Vert.x verticle, then:
-
gradle shadowJar
builds an executable Jar with all dependencies:java -jar build/libs/simple-project-all.jar
-
gradle vertxRun
starts the application and automatically recompiles (gradle classes
) and reloads the code when any file undersrc/
is being added, modified or deleted.
A slightly more elaborated example
A project using vertx-web
and logback
would use a build.gradle
definition like the following one:
plugins {
id 'io.vertx.vertx-plugin' version 'x.y.z'
}
repositories {
jcenter()
}
dependencies {
compile "io.vertx:vertx-web" // (1)
compile "ch.qos.logback:logback-classic:1.2.3" // (2)
}
vertx {
mainVerticle = "sample.App"
vertxVersion = "4.1.2" // (3)
}
-
Part of the Vert.x stack, so the version can be omitted.
-
Logback needs a version.
-
You can override to point to any specific release of Vert.x.
Kotlin projects
This plugin works with Kotlin projects too:
plugins {
id 'io.vertx.vertx-plugin' version 'x.y.z'
id 'org.jetbrains.kotlin.jvm' version 'a.b.c'
}
repositories {
jcenter()
}
dependencies {
compile 'io.vertx:vertx-lang-kotlin'
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' // (1)
}
vertx {
mainVerticle = "sample.MainVerticle" // (2)
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { // (3)
kotlinOptions {
jvmTarget = "1.8"
}
}
-
This pulls all the Kotlin standard library dependencies for JDK 8+.
-
This verticle can be written in Kotlin (or Java).
-
By default Kotlin compiles to Java 6 bytecode, so it is worth changing all compilation tasks to match Java 8 bytecode.
Using Kotlin DSL
plugins {
id("io.vertx.vertx-plugin") version "x.y.z"
}
repositories {
jcenter()
}
vertx { // (1)
mainVerticle = "sample.App"
}
-
Extension method on
org.gradle.api.Project
.
Configuration
The configuration happens through the vertx
Gradle extension.
The following configuration can be applied, and matches the vertx run
command-line interface when possible:
Option | Description | Default value |
---|---|---|
|
the Vert.x version to use |
|
|
the main class name |
|
|
the main verticle |
|
|
a list of command-line arguments to pass |
|
|
either a file or direct JSON data to provide configuration |
|
|
the working directory |
|
|
extra JVM arguments |
|
|
whether automatic redeployment shall happen or not |
|
|
Ant-style matchers for files to watch for modifications |
[ |
|
the Gradle tasks to run before redeploying |
|
|
tuning for the redeployment watch timers |
|
|
The debugger port |
|
|
Whether or not the application must wait until a debugger is attached to start |
|
The default values are listed in src/main/kotlin/io/vertx/gradle/VertxExtension.kt
.
By default redeployment is enabled, running gradle classes
to recompile, and watching all files under src/
.
Licensing
Copyright 2017-2019 Red Hat, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Credits
The plugin was originally created by Julien Ponge.
Thanks to the folks at Gradle for their guidance and technical discussions:
-
Cédric Champeau
-
Stefan Oheme
-
Rodrigo B. de Oliveira
-
Eric Wendelin
-
Benjamin Muschko
Thanks also to all the contributors to this project.