Create a service

From scratch

To build Hexagon services you have some Gradle helpers that you can use on your own project. To use them, you can use the online versions, or copy them to your gradle directory.

You can write a [Gradle] project from scratch (Gradle 4 or newer is required):


plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.0'

apply plugin: 'kotlin'
apply plugin: 'application'

mainClassName = 'HelloKt'

repositories {
    jcenter ()

dependencies {
    compile ("com.hexagonkt:server_jetty:0.23.7")

Now you can run the service with gradle run and view the results at: http://localhost:2010/hello/world

From a template

You can create a service from a [Lazybones] template. To do so type: lazybones create hexagon-service service

curl -s | bash && source ~/.sdkman/bin/
sdk i lazybones
mkdir ~/.lazybones # Bug with Lazybones?
lazybones config set bintrayRepositories pledbrook/lazybones-templates jamming/maven
lazybones create hexagon-service service -Pgroup=org.example -Pversion=0.1 -Pdescription=Description
cd service

Directory structure

The project uses the standard Gradle structure. Gradle wrapper changed to be stored in the gradle folder instead of the project root

Running and Testing

gw run gw -x test -t runService # Continuous mode AKA watch

Packaging and Deployment

Build scripts:

  • kotlin.gradle: Sets up Kotlin’s Gradle plugin: Adds Kotlin libraries, setup coverage report, filter project resources with build variables. To use it you need to:
    • Define the kotlinVersion variable to file.
    • Add the following code to build.gradle
      buildscript {
          repositories {
              jcenter ()

          dependencies {
              classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
  • service.gradle: Gradle’s script for a service or application.

    Tasks: - runService: for continuous run (AKA “Watch”) - buildInfo / processResources

  • site.gradle: Adds support for site generation (with API documentation and reports).

    • siteSource
    • siteTarget

    To apply this script, you need to add the JBake plugin manually at the top of your build script as that is not possible in included scripts like this one. These are the required lines to do so:

    plugins {
        id 'org.xbib.gradle.plugin.jbake' version '1.2.1'

Configuration files

  • service.yaml (see
  • logback.xml