forked from ktorio/ktor-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuto_reload.xml
158 lines (149 loc) · 6.72 KB
/
Auto_reload.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic SYSTEM "https://resources.jetbrains.com/stardust/html-entities.dtd">
<topic xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/stardust/topic.v2.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
title="Auto-reload"
id="Auto_reload">
<microformat>
<p>
<b>Code examples</b>:
<a href="https://github.com/ktorio/ktor-documentation/tree/%current-branch%/codeSnippets/snippets/autoreload-engine-main">autoreload-engine-main</a>,
<a href="https://github.com/ktorio/ktor-documentation/tree/%current-branch%/codeSnippets/snippets/autoreload-embedded-server">autoreload-embedded-server</a>
</p>
</microformat>
<excerpt>
Ktor allows you to use Auto-reload to reload application classes on code changes.
</excerpt>
<p>
<a href="running.md">Restarting</a> a server during development might take some time.
Ktor allows you to overcome this limitation by using <emphasis>Auto-reload</emphasis>, which reloads application classes on code changes and provides a fast feedback loop.
To use Auto-reload, follow the steps below:
</p>
<list type="decimal">
<li>
<p>
<a anchor="enable">Enable the development mode</a>
</p>
</li>
<li>
<p>
(Optional) <a anchor="watch-paths">Configure watch paths</a>
</p>
</li>
<li>
<p>
<a anchor="recompile">Enable recompiling on changes</a>
</p>
</li>
</list>
<chapter title="Enable the development mode" id="enable">
<p>
To use Auto-reload, you need to enable the
<a href="development_mode.xml" anchor="enable">development mode</a> first.
This depends on the way you used to <a href="create_server.xml">create and run a server</a>:
</p>
<list>
<li>
<p>
If you use <code>EngineMain</code> to run a server, enable development mode
in the <a href="development_mode.xml" anchor="application-conf">application.conf</a> file.
</p>
</li>
<li>
<p>
If you run a server using <code>embeddedServer</code>, you can use the
<a href="development_mode.xml" anchor="system-property">io.ktor.development</a>
system property.
</p>
</li>
</list>
<p>
When development mode is enabled, Ktor will be watching output files from the working directory automatically.
If required, you can narrow down a set of watched folders by specifying
<a anchor="watch-paths">watch paths</a>.
</p>
</chapter>
<chapter title="Configure watch paths" id="watch-paths">
<p>
When you <a anchor="enable">enable</a> development mode,
Ktor starts watching output files from the working directory.
For example, for a <path>ktor-sample</path> project build with Gradle the following folders
will be watched:
</p>
<code style="block">
ktor-sample/build/classes/kotlin/main/META-INF
ktor-sample/build/classes/kotlin/main/com/example
ktor-sample/build/classes/kotlin/main/com
ktor-sample/build/classes/kotlin/main
ktor-sample/build/resources/main
</code>
<p>
Watch paths allow you to narrow down a set of watched folders.
To do this, you can specify a part of a watched path.
For example, to monitor changes in the <path>ktor-sample/build/classes</path> subfolders,
pass <code>classes</code> as a watch path.
Depending on the way you use to run a server, you can specify a watch path in the following ways:
</p>
<list>
<li>
<p>
In the <path>application.conf</path>, specify the <code>watch</code> option:
</p>
<code style="block" src="snippets/autoreload-engine-main/src/main/resources/application.conf" lines="1-3,5-6,11"/>
<p>
You can specify several watch paths separated by a comma, for example:
</p>
<code style="block">
watch = [ classes, resources ]
</code>
<p>
You can find the full example here: <a href="https://github.com/ktorio/ktor-documentation/tree/%current-branch%/codeSnippets/snippets/autoreload-engine-main">autoreload-engine-main</a>.
</p>
</li>
<li>
<p>
If you are using <code>embeddedServer</code>, pass a watch path as the <code>watchPaths</code> parameter:
</p>
<code style="block" lang="Kotlin" src="snippets/autoreload-embedded-server/src/main/kotlin/com/example/Application.kt" lines="10-16"/>
<p>
You can find the full example here: <a href="https://github.com/ktorio/ktor-documentation/tree/%current-branch%/codeSnippets/snippets/autoreload-embedded-server">autoreload-embedded-server</a>.
</p>
</li>
</list>
</chapter>
<chapter title="Recompile on changes" id="recompile">
<p>
Since Auto-reload detects changes in output files,
you need to rebuild a project.
You can do this manually in IntelliJ IDEA or
enable continuous build execution in Gradle using the <code>-t</code> command-line option.
</p>
<list>
<li>
<p>
To rebuild a project manually in IntelliJ IDEA, select
<menupath>Build | Rebuild Project</menupath> from the main menu.
</p>
</li>
<li>
<p>
To rebuild a project automatically using Gradle,
you can run the <code>build</code> task with the <code>-t</code> option in a terminal:
</p>
<code style="block">
./gradlew -t build
</code>
<tip>
<p>
To skip running tests when reloading a project, you can pass the <code>-x</code> option to the <code>build</code> task:
</p>
<p>
<code style="block">
./gradlew -t build -x test -i
</code>
</p>
</tip>
</li>
</list>
</chapter>
</topic>