Search code examples
grailsgradlebootrun

How to run a Grails 3 app locally with https using gradle bootRun


We have a complicated, multi-module project that for various reasons must be run with 'gradle bootRun' and not 'grails run-app'. With 'grails run-app' it is easy to run in an https environment locally by using 'grails run-app -https', but this does not work for gradle bootRun and I could not find an obvious equivalent. Is there something I can add to my build file, or pass as a parameter, to mimick the -https behaviour of grails run-app when running locally on a developer machine?

EDIT: I'm using the default embedded servlet container (Tomcat)


Solution

  • I was able to solve this with the following steps:

    1. Create a local keystore as per the instructions at https://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html#Configuration - in particular this command (using 'mysecret' when prompted for a password, this is your choice obviously)

      $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA -keystore ./localkeystore

    2. Copy the generated localkeystore file into the root of my project alongside build.gradle

    3. Add the following block to build.gradle:

    -

    bootRun {
        systemProperty 'server.port', '8443'
        systemProperty 'server.ssl.enabled', 'true'
        systemProperty 'server.ssl.key-store', './localkeystore'
        systemProperty 'server.ssl.key-store-password', 'mysecret'
        systemProperty 'server.ssl.key-password', 'mysecret'   
    }