When I add the `io.ktor:ktor-server-config-yaml-jv...
# kvision
m
When I add the
io.ktor:ktor-server-config-yaml-jvm
dependency to a project, and build the
jar
task, the default
io.ktor.server.config.HoconConfigLoader
is not being added to the list of ConfigLoaders in
META-INF/services/io.ktor.server.config.ConfigLoader
This has the knock on effect that the "application.conf" file in the root of the jar is not able to be loaded, as there is no ConfigLoader class available to handle that file type. See thread. I've reproduced this in the examples application.
I've tracked it down to the fact the class is missing from the ConfigLoader in the jar file. Do you know how I can force that in when building the kvision fat jar? This file in the jar:
Copy code
META-INF/services/io.ktor.server.config.ConfigLoader
is missing this entry when you include the YAML config loader in the dependencies:
Copy code
io.ktor.server.config.HoconConfigLoader
I've found that in the addressbook fullstack ktor application, the file does contain the Hocon loader (as it's the default), however, if I add this dependency to the project:
Copy code
implementation("io.ktor:ktor-server-config-yaml-jvm:$ktorVersion")
Then it swaps to only the Yaml config loader:
Copy code
io.ktor.server.config.yaml.YamlConfigLoader
It seems that the default Hocon config is not listed if the Yaml one is included when building the jar file, but is when loading via IDE / jvmRun. I think this should work, if you start the application via the "jvmRun" task (i.e. non JAR), then both ConfigLoader classes are loaded, but not through just running the jar file.
r
I can't really help you because I'm not even the author of the
shadowJar
task code. It was contributed very long time ago and it is still used: https://github.com/rjaros/kvision/blob/master/kvision-tools/kvision-gradle-plugin/src/main/kotlin/io/kvision/gradle/KVisionPlugin.kt#L305-L314
The task just takes the list of files from
jvmRuntimeClasspath
configuration, but I have no idea what it really means 🙂
It is possible it somehow conflicts with Ktor runtime configuration, but I don't know how to fix this.
m
Thanks! It's not a major concern, certainly not for me, as it's a small project and I can use either yaml or hocon. It's only an issue for anyone wanting to use both for some reason. I did ask this in #C0A974TJ9 too (link here) I've some history with writing gradle plugins myself. I might have a look if there are any obvious bits in ktor's plugins that provide their own fatJar task that does something here. The kvision plugin doesn't seem to target the config loader specifically from a brief look, so may require deeper investigation.