Groovy

Building Vert.x projects using Gradle

We currently useĀ Vert.x in several internal and external projects. Until the most recent project we whereĀ building our Vert.x modules using Maven.

Gradle isĀ our build tool of choice, but the defaultĀ approach described at the Vert.x siteĀ caused several issues:

  • The task of cloning, cleaning and configuring the template project is error-prone;
  • The template projectĀ does not support recent Gradle versions >= 2.x;
  • This approach is not compatible with the Gradle support in IntelliJ IDEA.

While starting our most recent project we investigated the possibility of using Gradle again. Instead of using the approach described atĀ the Vert.x site we are using the excellent Vert.x Gradle plugin provided byĀ Daryl Teo.

Using the following Gradle build fileĀ we are able to build and run our project from Gradle and import it successfully into IntelliJ IDEA:

build.gradle

// Configure the dependencies for our build script
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        // Specify our dependency on the marvelous plugin from Daryl Teo
        classpath 'com.darylteo.vertx:vertx-gradle-plugin:0.1.3'
    }
}
// Apply the Groovy plugin to compile our Groovy code
apply plugin: 'groovy'

// Apply the Vertx plugin
apply plugin: 'vertx'

repositories {
    jcenter()
}

// Specify the project dependencies
dependencies {
    compile "org.codehaus.groovy:groovy-all:2.3.3"
}

// Configure Vertx
vertx {
    platform {
        // Specify Vert.x version
        version '2.1.5'
        // Language used
        lang 'groovy'
    }

    // Configuration of the module using Vert.x fields using camelcased names
    // See: http://vertx.io/mods_manual.html#module-descriptor-file-modjson
    config {
        main 'groovy:com.jdriven.demo.MainVerticle'
    }

    // Specify the config file to pass to Vert.x using -conf when executing the runMod task
    deployments {
        mod {
            platform {
                conf 'config/vertx/dev.json'
            }
        }
    }
}

Using this configuration exposes the following Vert.x related Gradle tasks:

  • modZip : Creates the module zip
  • debugMod : Run the module including remote debugging
  • runMod : Run the module

More information regarding this marvellous Gradle Vert.x plugin can be found at: https://github.com/darylteo/vertx-gradle-plugin.

Note that the credits for theĀ Vert.x Gradle plugin fully go to Daryl Teo. This post is only meant to raise the awareness of theĀ existenceĀ of the plugin and to complement him for his great work.

Reference: Building Vert.x projects using Gradle from our JCG partner Rob Brinkman at the JDriven blog.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button