No configuration setting found for key 'ktor'
Run exception
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'ktor'
at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:170)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:184)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:189)
at com.typesafe.config.impl.SimpleConfig.getObject(SimpleConfig.java:264)
at com.typesafe.config.impl.SimpleConfig.getObject(SimpleConfig.java:37)
at io.ktor.server.engine.CommandLineKt$commandLineEnvironment$environment$1.invoke(CommandLine.kt:57)
at io.ktor.server.engine.CommandLineKt$commandLineEnvironment$environment$1.invoke(CommandLine.kt)
at io.ktor.server.engine.ApplicationEngineEnvironmentBuilder.build(ApplicationEngineEnvironment.kt:55)
at io.ktor.server.engine.ApplicationEngineEnvironmentKt.applicationEngineEnvironment(ApplicationEngineEnvironment.kt:38)
at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:50)
at io.ktor.server.netty.DevelopmentEngine.main(DevelopmentEngine.kt:13)
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.Coroutines
val ktor_version = "0.9.3"
plugins {
application
kotlin("jvm") version "1.2.51"
}
application {
mainClassName = "io.ktor.server.netty.DevelopmentEngine"
}
group = "ktor3"
version = "1.0-SNAPSHOT"
repositories {
jcenter()
maven("http://kotlin.bintray.com/ktor")
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("ch.qos.logback:logback-classic:1.2.1")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental.coroutines = Coroutines.ENABLE
}
application.conf
ktor {
deployment {
port = 8080
}
application {
modules = [ com.kodal.AppKt.main ]
}
security {
}
}
App.kt
package com.kodal
import io.ktor.application.Application
import io.ktor.application.call
import io.ktor.application.install
import io.ktor.features.CallLogging
import io.ktor.features.DefaultHeaders
import io.ktor.response.respondText
import io.ktor.routing.Routing
import io.ktor.routing.get
fun Application.main() {
install(DefaultHeaders)
install(CallLogging)
install(Routing) {
get("/") {
call.respondText("Hello")
}
}
}
Well, it looks that your application.conf is not in the right place, or that you are not defining any resources sourceSet.
That exception happens when the application.conf is not read, and thus that required setting is not set.
I have added a section in the FAQ covering this: http://ktor.io/quickstart/faq.html#cannot-find-application-conf
I think it's in the right place and defined sourceSet
http://ktor.io/quickstart/quickstart/intellij-idea/gradle.html#extract-out-configuration-data
Try to generate a sample project with this and try if it happens to you there: http://ktor.io/quickstart/generator.html
I tried with intellij idea plugin and online generator, same exception
Let's check a few things:
- In the images you are using the gradle kotlin-dsl, have you tried without it? (generator do not use it, so I guess if you tried with it, it is not related to it, but let's confirm it)
- Which IntelliJ version are you using?
- Which Java version have you installed and configured?
- Which Kotlin version have you in the IDE?
Tools -> Kotlin -> Configure Plugin updates - Have you tried to run it from the terminal
./gradlew run? Maybe your IntelliJ/Kotlin in the IDE has something wrong
I tried with terminal and it worked. Intellij IDEA 2018.2 RC
Can you join slack https://slack.kotlinlang.org/ #ktor channel and continue the troubleshooting there?
Ok
I met this too when I create ktor project with kotlin gradle dsl.
build.gradle.kts
kotlin.sourceSets["main"].kotlin.srcDirs("src")
kotlin.sourceSets["test"].kotlin.srcDirs("test")
I think it should contains sources dir like this
kotlin.sourceSets["main"].resources.srcDirs("resources"))
but it doesn't work @soywiz
Have you used the Ktor IntelliJ plugin for creating the build.gradle.kts?
Yes,it only contains
kotlin.sourceSets["main"].kotlin.srcDirs("src")
kotlin.sourceSets["test"].kotlin.srcDirs("test")
Should be fixed in the next version: https://github.com/ktorio/ktor-init-tools/commit/31d183f9da0f7ee3ef7877dabf3d643ae2c32779
Thanks, but I want to know why it didn't work after I added
kotlin.sourceSets["main"].resources.srcDirs("resources"))
manually
I've also manually added the resources directory to my sourceSets and still have the given error. Is the change actually going to fix the issue?
@ti4n1993 , @randallmitchell , you should add resources folder without kotlin prefix
kotlin.sourceSets["main"].kotlin.srcDirs("src")
sourceSets["main"].resources.srcDir("resources")
kotlin.sourceSets["test"].kotlin.srcDirs("test")
Thanks