ktor icon indicating copy to clipboard operation
ktor copied to clipboard

No configuration setting found for key 'ktor'

Open kodal opened this issue 8 years ago • 16 comments

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")
        }
    }
}

kodal avatar Jul 18 '18 11:07 kodal

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

soywiz avatar Jul 18 '18 12:07 soywiz

I think it's in the right place and defined sourceSet

http://ktor.io/quickstart/quickstart/intellij-idea/gradle.html#extract-out-configuration-data

kodal avatar Jul 18 '18 12:07 kodal

Try to generate a sample project with this and try if it happens to you there: http://ktor.io/quickstart/generator.html

soywiz avatar Jul 18 '18 13:07 soywiz

I tried with intellij idea plugin and online generator, same exception

kodal avatar Jul 18 '18 13:07 kodal

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

soywiz avatar Jul 18 '18 13:07 soywiz

I tried with terminal and it worked. Intellij IDEA 2018.2 RC

kodal avatar Jul 18 '18 13:07 kodal

Can you join slack https://slack.kotlinlang.org/ #ktor channel and continue the troubleshooting there?

soywiz avatar Jul 18 '18 13:07 soywiz

Ok

kodal avatar Jul 18 '18 13:07 kodal

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

ti4n1993 avatar Oct 15 '18 07:10 ti4n1993

Have you used the Ktor IntelliJ plugin for creating the build.gradle.kts?

soywiz avatar Oct 15 '18 10:10 soywiz

Yes,it only contains kotlin.sourceSets["main"].kotlin.srcDirs("src") kotlin.sourceSets["test"].kotlin.srcDirs("test")

ti4n1993 avatar Oct 15 '18 10:10 ti4n1993

Should be fixed in the next version: https://github.com/ktorio/ktor-init-tools/commit/31d183f9da0f7ee3ef7877dabf3d643ae2c32779

soywiz avatar Oct 15 '18 11:10 soywiz

Thanks, but I want to know why it didn't work after I added

kotlin.sourceSets["main"].resources.srcDirs("resources"))

manually

ti4n1993 avatar Oct 15 '18 12:10 ti4n1993

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?

randallmitchell avatar Oct 22 '18 04:10 randallmitchell

@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")

laeur avatar Oct 25 '18 06:10 laeur

Thanks

ti4n1993 avatar Oct 25 '18 07:10 ti4n1993