Last Updated: February 25, 2016
·
15.79K
· johnnywey

Run Application in Debug from Gradle

Let's say you have an application that is built with Gradle and deployed stand-alone (e.g. using the Gradle application plugin). A great example of this use case is an HTTP server built on Netty as opposed to using the Servlet API.

You want to debug the application. Since it's not running in a container, the standard mechanism of debugging via Jetty is not available to you.

A solution is to augment your JavaExec task with another task that will allow execution of the process in debug. Simply add something similar to the following to your build.gradle:

task(runDebug, dependsOn: 'classes', type: JavaExec) {
    main = "com.mything.server.HttpServer"
    classpath = sourceSets.main.runtimeClasspath
    jvmArgs = ["-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"]
}

And BAM you're off to the races on port 5005!