Kotlin > Ktor > Auto Reload 사용

4368 단어 KtorKotlin
다음과 같은 느낌으로 소스 변경에 Auto Reload가 걸릴 수 있습니다.



설정 파일



application.conf에 다음을 추가합니다.
  • development: true 로 한다
  • watch: 모니터링 대상.
    이 경우에는 /build/classes가 감시 대상이 된다.

  • application.conf
    ktor {
        deployment {
            port = 8080
            port = ${?PORT}
            watch = [ classes ]
        }
        application {
            modules = [ com.example.ApplicationKt.module ]
        }
        development = true
    }
    

    watch는 그 밖에도 다음과 같이 설정할 수 있는 모양
    watch = [ / ]
    watch = [ classes, resources ]
    

    Auto-reload | Ktor

    모니터링 작업 시작



    terminal에서 다음을 수행하여 소스가 변경되면 다시 빌드해야 합니다.
    gradle -t installDist
    
      or (↑どちらかお好きな方で↓)
    
    gradlew -t build
    

    작업이 시작됩니다.
    gradle -t installDist
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
    
    BUILD SUCCESSFUL in 765ms
    6 actionable tasks: 6 up-to-date
    
    Waiting for changes to input files of tasks... (ctrl-d to exit)
    <-------------> 0% WAITING
    > IDLE
    

    실행



    평소대로 실행한다.

    아래와 같이 Watching이 표시되면 OK
    2021-08-12 12:46:38.361 [main] DEBUG Application - Java Home: /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents
    2021-08-12 12:46:38.362 [main] DEBUG Application - Class Loader: jdk.internal.loader.ClassLoaders$AppClassLoader
    2021-08-12 12:46:38.370 [main] DEBUG Application - Watching /Users/atsu/Downloads/ktor-autoreload/build/classes/kotlin/main/com/example for changes.
    2021-08-12 12:46:38.370 [main] DEBUG Application - Watching /Users/atsu/Downloads/ktor-autoreload/build/classes/kotlin/main for changes.
    2021-08-12 12:46:38.370 [main] DEBUG Application - Watching /Users/atsu/Downloads/ktor-autoreload/build/classes/kotlin/main/META-INF for changes.
    2021-08-12 12:46:38.370 [main] DEBUG Application - Watching /Users/atsu/Downloads/ktor-autoreload/build/classes/kotlin/main/com for changes.
    2021-08-12 12:46:38.775 [main] INFO  Application - Responding at http://0.0.0.0:8080
    

    변경



    소스를 변경하면 gradle -t installDist가 변경을 감지하고 다시 빌드됩니다.
    modified: /Users/atsu/Downloads/ktor-autoreload/src/Application.kt
    Change detected, executing build...
    
    
    > Task :compileKotlin
    w: /Users/atsu/Downloads/ktor-autoreload/src/Application.kt: (12, 24): Parameter 'testing' is never used
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
    
    BUILD SUCCESSFUL in 850ms
    6 actionable tasks: 5 executed, 1 up-to-date
    
    Waiting for changes to input files of tasks... (ctrl-d to exit)
    <<=============> 100% EXECUTING [1m 28s]
    > IDLE
    

    기타



    GraphQL 디버깅에도 유용 할 것 같습니다.



    참고



    Auto-reload | Ktor

    좋은 웹페이지 즐겨찾기