Closed realmhamdy closed 3 years ago
I also think that having to use the project folder name as an autoreload setting is not reliable because it can differ from a developer to the next as it's not checked out in source control.
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
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.
Not sure about the others, but my default value is 'IntelliJ IDEA', so it didn't work before changing the configuration.
I set the Gradle JVM from JDK 11 to JDK 8, then it works fine for me now. I'm using Jetty
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?
@cy6erGn0m @orangy @e5l This should be super high priority. Since autoreload never works, it really worsens the development experience 😿
@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.
This is a tough one! I used a combination of the advice posted above in order to get mine working. Thanks to the various contributors who helped in this thread.
Configured IntelliJ with a Run/Debug config for this project. Note the use of installDist
task (not build
):
I started that task in IntelliJ. Then in the command line did the following:
gradle run
I am using JDK 8, which seems important based on the advice given above, and the docs provided by the team:
Incidentally I have the gradle watch config in my gradle.properties
. Might not be related, but at this point I'm afraid to change it :wink:
org.gradle.unsafe.watch-fs=true
I'm using Gradle 6.5.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
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
It needs a lot of settings to allow this auto reload, because? (And after all it still didn't work here :/) Because not works with jdk11?
Vert.x for example does not need to run with a parameter to hot reload, and is defined in initial start, this implementation would take a long time?
Hey @joaoeudes7, could you check https://ktor.io/docs/development-mode.html?
Those of us running the Flatpack version do not have access to the JAVA_HOME
and thus cannot run the terminal commands through the integrated terminal.
The (mildly annoying) way around this is two have two different run configurations. One is the standard Ktor run/debug config, the other is one that watches the directory. Here's what I did:
I will say, I love Intellij and I am loving Ktor so far, but it is kinda odd that auto reload doesn't just work "automagically" when the language, IDE, and framework are are "controlled" by the same company (at least to some extent). I'm sure it'll get there with time, I know Jetbrains has a lot of projects in the oven.
example of auto-reload on backend/frontend with Ktor+React with Kotlin 1.8.0 and new IR: https://github.com/alexoooo/sample-ktor-react
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
. Myapplication.conf
looks like this: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:I also tried
com.company
instead ofMyProjectFolder
in the watch list but that one is even worse. The run output shows autoreload is disabled.