Skip to content

Instantly share code, notes, and snippets.

@zedar
Last active July 18, 2019 13:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zedar/ca00d5731e6ed2ac6500 to your computer and use it in GitHub Desktop.
Save zedar/ca00d5731e6ed2ac6500 to your computer and use it in GitHub Desktop.
ratpack gradle & watch for changes

Ratpack and runtime class reloading

Ratpack works very smoothly with spring-loaded library. It is defined as dependency in build.gradle file. Spring-loaded enables runtime hot class reloading.

dependencies {
    springloaded "org.springframework:springloaded:1.2.0.RELEASE"
}

But default configuration reloads only changes in Ratpack.groovy file.

There are two solutions for hot reloading classes from src/main folder.

Class reloading with manual command ./graldew classes

In one terminal window run:

$ ./gradlew run

Once you save changes in source files in another terminal window run:

$ ./gradlew classes

This command compiles changes and then spring-loaded reloads them in memory.

Class reloading with gradle-watch plugin

Put the following dependencies to the build.gradle file:

buildscript {
    repositories {
        maven { url "http://oss.jfrog.org/artifactory/repo" }
        jcenter()
    }
    dependencies {
        classpath "io.ratpack:ratpack-gradle:0.9.8"
        classpath 'com.bluepapa32:gradle-watch-plugin:0.1.3'
    }
}

Apply plugin:

apply plugin: "watch"

Add new task definition (watch for changes in src/main/groovy):

watch {
    groovy {
        files fileTree(dir: "src/main/groovy", include: "**/*.groovy")
        tasks "classes"
    }
}

In one terminal window run command:

$ ./gradlew run

In another terminal window run one more command:

$ ./gradlew watchRun

One you save changes in source files watch command catches them, compiles classes and then spring-loaded library reloads them in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment