Vert.x is an incredible toolkit for developing high-performance applications.
This plugin can speed up your dev cycle in popular build systems, such as Maven.
Write your code and see the changes auto reload into your JVM. Fully debuggable.
This plugin was originally written for personal use. Its shared here under the MIT licence.
Contributions most gratefully received and recognised.
- Detect source changes
compile
stale targets- Hot Reload
- Full Debug without needing to attach to secondary processes
- Intuitive integration with Maven toolchain
- Fast at least much faster than using a manual workflow
Release versions of the Maven plugin are available in Maven Central. Snapshots are available in Sonatype. Zip'd releases are available here.
Please note: the latest version of the plugin depends on vert.x 3.1.0
.
Add the following to your project pom.xml
:
<plugin>
<groupId>io.dazraf</groupId>
<artifactId>vertx-hot-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<verticleReference>class or service name</verticleReference>
<configFile>config filename</configFile>
</configuration>
</plugin>
The configuration
has the following elements:
Required
verticleReference
- either the fully-qualified reference to the top-level verticle of your application or a service reference.
Optional
-
configFile
- the class path to the verticle configuration file. When loaded,vertx:hot
will add the property"devmode": true
. -
liveHttpReload
- whentrue
, all web pages served by the application verticles will auto reload when any source is changed.default: true
-
buildResources
- when set totrue
, any change to files under the resource directories will trigger acompile
. Use this if your resources generate sources.default: false
-
notificationPort
- websocket port for browser notifications. Used in conjunction withliveHttpReload: true
. Default is9999
. -
extraPaths
- list of additional paths to be watched. This has a list of<extraPath>
elements. Example as follows:
<extraPaths>
<extraPath>
<path>specialPath/causesRedeploy.md</path>
<!-- default -->
<!-- <action>Redeploy</action> -->
</extraPath>
<extraPath>
<path>specialPath/causesCompile.md</path>
<action>Recompile</action>
</extraPath>
<extraPath>
<path>specialPath/causesRefresh.md</path>
<action>Refresh</action>
</extraPath>
</extraPaths>
You can run it either on the command line with:
mvn vertx:hot
Or, in your favourite IDE:
-
For any IDE you'll need a locally installed maven installation. Bundled / Embedded maven installations do not work.
-
IntelliJ IDEA:
- Run - open the Maven side-bar, expand the
Plugins/vertx
section and double-click onvertx:hot
goal. Any changes to your project's main source (e.g.src/main
) will cause a hot deploy. - Debug - right-click on the
vertx:hot
goal and selectDebug
.
- Run - open the Maven side-bar, expand the
-
Eclipse:
- Run - create maven build runner for
vertx:hot
goal. For Eclipse Mars on OS X, I found I had to set the JAVA_HOME environment variable in the runner. Once setup,Run
it. - Debug - as above, but instead of
Run
,Debug
- Run - create maven build runner for
Press either: <Enter>
or Ctrl-C
.
There are two simple test project under example1
and example2
.
The latter is an adaption of the excellent ToDo App
by Scotch, with a vert.x reactive flavour.
To run either:
- You will need bower on your path.
- After running
mvn clean install
in the parent directory cd example1
orcd example2
mvn vertx:hot
- Browse to http://localhost:8888
- Open up the project in your favourite IDE/Editor and try changing some code or static resources
- The browser will automatically reload. The IDE/shell console will show the unload | recompile | reload activity.
Buck is an efficient build system capable of identifying and recompiling only what it absolutely has to.
Before you rush off to switch from Maven/Gradle to Buck, it's important to bear in mind that Buck is not (and doesn't intend to be) as featureful as Maven. If you're used to transitive dependency retrieval, haven't heard of the concept of checking-in dependencies, leverage multitudinous Maven plugins, have developed custom Maven plugins, regularly rely on your build system's strong IDE integration, or just need things to work "out-of-the-box", then Buck might not be for you. However, if you are looking for outrageously fast builds, are prepared to rethink your project structure, and if the concepts behind Buck resonate for you, then you may want to give it a try.
The Buck support in vertx-hot is presently both limited and inefficient, but is hopefully sufficient to be of use to simple projects. As always, feature and pull requests are most welcome.
The vertx-hot-buck build produces a fat-jar, to make inclusion from Buck projects fairly simple.
A few dependencies have been excluded, either due to shading complexities or to improve flexibility:
- Vertx - likely already on your classpath. We build against 3.1.0, but more recent versions should be fine too.
- SLF4J - the logging API. Drop in
slf4j-api
and your chosen implementation. We build against 1.7.12, but again this should be fairly flexible. - Buck - expected to reside on your PATH
If you're checking-in dependencies to your VCS, as per the recommended Buck methodology, then:
- Store the vertx-hot-buck jarfile in your lib directory
- Reference it using a
prebuilt_jar
rule:
prebuilt_jar(
name = 'vertx-hot-buck',
binary_jar = 'lib/vertx-hot-buck.jar'
)
If you fetch libraries from an m2 compatible repository, then you can include a corresponding remote_file
rule to perform the fetch.
An easy way to configure a buck hot deploy target is with a dedicated main class.
You'll likely want to configure the logger:
System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
Then configure your hot deployment:
BuckHotDeployBuilder.create()
.withBuildTarget("//my-service:bin")
.withProjectRootPath(".")
.withHotDeployConfig(new HotDeployParameters()
.withBuildResources(true)
.withCompileSourcePaths(asList("my-service/java"))
.withNotificationPort(9588)
.withVerticleReference("io.dazraf.myservice.MyVerticle")
)
.build()
.run();
Executing the main method, with an appropriate classpath, will start the hot deployment.
The buck deployment parameters are:
Required
withBuildTarget
- The Buck build target to invoke when a filesystem change is detected.
Optional
-
withProjectRoot
- a relative path to your project's root. Defaults to the present working directory. -
withFetchMode
- if you'll be updatingremote_file
rules that need fetching before each build, you can set a non-manualFetchMode
. At present, this uses a crude & inefficient implementation.
The hot deployment configuration options are described in the Maven installation instructions.
With many thanks: