ktor: Code autoreload not working for me

Ktor Version

1.1.3

Ktor Engine Used(client or server and name)

EngineMain I guess?

JVM Version, Operating System and Relevant Context

JDK 1.8. Windows 10

Feedback

Okay I have a new project generated using the Ktor IDEA plugin. I’m just trying to make autoreload work (which should by default?). I have only one Kotlin file in src/Application.kt. My application.conf looks like this:

ktor {
    deployment {
        port = 8080
        port = ${?PORT}
        autoreload = true
        watch = [ MyProjectFolder ]
    }
    application {
        modules = [ com.company.ApplicationKt.module ]
    }
}

The issue is, when I change Application.kt the project doesn’t reload and the changes are not reflected in the browser. I see this in the run output:

2019-02-25 11:01:46.894 [main] DEBUG Application - Watching F:\Projects\MyProjectFolder\out\production\classes for changes.
2019-02-25 11:01:46.895 [main] DEBUG Application - Watching F:\Projects\MyProjectFolder\out\production\classes\com for changes.
...

I also tried com.company instead of MyProjectFolder in the watch list but that one is even worse. The run output shows autoreload is disabled.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

@cy6erGn0m @orangy @e5l This should be super high priority. Since autoreload never works, it really worsens the development experience 😿

Same here, I’d also say the documentation on this is just very not clear unfortunately, so it’s very hard to know where to go with it… especially on maven - I had to swap to gradle to get it working at all but now it seems to have just stopped working altogether

I believe I found the cause of this issue.

if I simply run with Intellij, compiled classes go to <ProjectFolder>/out/production/. reference.

if you watch source changes by running gradle -t watch, the sources are compiled to <ProjectFolder>/build/classes/. These two paths are different and ktor application is not watching the class files <ProjectFolder>/build/classes/.

To solve this issue, one should avoid using intellij to run the ktor application. Use gradle -t watch to watch file changes and use gradle run to start the application.

Hope this helps

@AdityaAnand1 from intelliJ simply create new run configuration and select gradle. For task put build and for arguments put -t. After that, run this task and while running it, also run your Ktor project. Make sure you are using Java 8.

How to use gradle run? The default project gives me no gradle executable (though there is a gradle.bat but I’m on MacOS)

Using gradlew does not work

@Ykid how did you get this to work?

Thank you very much @Ykid for the suggestion.

In case you chose Gradle and build the application from IntelliJ, this is what I did to make autoreload work.

IntelliJ Gradle settings screen accessed from File, Settings, choose 'Build, Execution, Deployment', 'Build Tools' and Gradle

Not sure about the others, but my default value is ‘IntelliJ IDEA’, so it didn’t work before changing the configuration.

To the person, who will go through this thread and wouldn’t understand how to fix the subj, official documentation describes it clearly now: https://ktor.io/docs/autoreload.html?topic=open-source#recompiling-automatically-on-source-changes

I set the Gradle JVM from JDK 11 to JDK 8, then it works fine for me now. I’m using Jetty

image