Hi all I have this curious bug with configuration cache that I do not know how to debug. How can I debug environment variables with HOCON when using gradle run?
It’s a ktor-application that use HOCON (application.conf). HOCON reads environment variables and the application is started with ./gradlew :project:run
. Whenever the environment variable changes I need to bust the configuration cache with --no-configuration-cache
, or else the application gets the previous value. All team members can reproduce in the same project, with different operating systems (Mac, Linux), but I’m unable to reproduce with a minimal example. Therefor I’m pretty sure this is a configuration issue, not a bug, but I may be mistaken.
The code in question:
fun main(args: Array<String>): Unit = io.ktor.server.cio.EngineMain.main(args)
@Suppress("unused", "LongMethod")
fun Application.module(init: ApplicationSpec.() -> Unit = {}) {
val someEnv = environment.config.property("some.env").getString()
val someEnvFromEnvironment = System.getenv("SOME_ENV")
log.info("SOME_ENV: '$someEnv'")
log.info("Environment SOME_ENV: '$someEnvFromEnvironment'")
// more config of the real application below
application.conf:
some.env = ""
some.env = ${?SOME_ENV}
Running (copied the relevant parts):
❯ export SOME_ENV=arve
❯ ./gradlew :person:run
Starting a Gradle Daemon, 2 busy Daemons could not be reused, use --status for details
Configuration on demand is an incubating feature.
Reusing configuration cache.
... logstatements from logback here
08:24:19.062 INFO Application - SOME_ENV: 'arve'
08:24:19.062 INFO Application - Environment SOME_ENV: 'arve'
Then updating the environment variable gives same results:
❯ export SOME_ENV=peder
❯ ./gradlew :person:run
Starting a Gradle Daemon, 3 busy Daemons could not be reused, use --status for details
Configuration on demand is an incubating feature.
Reusing configuration cache.
... logstatements from logback here
08:26:21.291 INFO Application - SOME_ENV: 'arve'
08:26:21.291 INFO Application - Environment SOME_ENV: 'arve'
Busting the cache gives wanted result:
❯ ./gradlew :person:run --no-configuration-cache
Starting a Gradle Daemon, 4 busy Daemons could not be reused, use --status for details
Configuration on demand is an incubating feature.
... logstatements from logback here
08:27:39.920 INFO Application - SOME_ENV: 'peder'
08:27:39.921 INFO Application - Environment SOME_ENV: 'peder'
If one want to see the whole setup, I’ve created a repo based of the gradle- and ktor init guides: GitHub - arve0/gradle-configuration-cache, but as said, this does not reproduce the error.
I’m mostly interested in how I would go to debug caching of environment variables in gradle.