zeugederunity
04/15/2022, 6:24 AMkotlin {
val ktorVersion: String by project /* 2.0.0 */
jvm { /* some blabla */ }
js { /* some blabla */ }
sourceSet {
val commonMain by getting { /* some blabla */ }
val jsMain by getting { /* some blabla */ }
val jvmMain by getting {
dependencies {
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
/*And some more */
}
}
val jvmTest by getting {
dependencies {
implementation("io.ktor:ktor-server-test-host:$ktorVersion")
}
}
}
}
The external libraries look like this:
/*ktor-server-auth has no jvmAndNixMain*/
Gradle: io.ktor:ktor-server-auth-jvm:2.0.0
Gradle: io.ktor:ktor-server-auth-jwt-jvm:2.0.0
Gradle: io.ktor:ktor-server-auto-head-response:jvmAndNixMain:2.0.0
Gradle: io.ktor:ktor-server-auto-head-respone:2.0.0
/*Some more libs with the each the corresponding jvmAndNixMain */
Gradle: io.ktor:ktor-server-core-jvm:jvmAndNixMain:2.0.0
Gradle: io.ktor:ktor-server-core-jvm:2.0.0
Is this a bug or does anyone know what I did wrong?
Thank you for your help in advance!Aleksei Tirman [JB]
04/15/2022, 8:51 AMjvmAndNixMain
dependencies?hfhbd
04/15/2022, 9:44 AMjvmAndNix
artifact 🤔 https://repo.maven.apache.org/maven2/io/ktor/Aleksei Tirman [JB]
04/15/2022, 9:53 AMhfhbd
04/15/2022, 9:58 AMnixAndJvmMain
? It should work too.zeugederunity
04/16/2022, 9:52 AMkotlin
fun initializeServer(applicationConfig: ApplicationConfig){
require(!initialized) {
"The server is already initialized!"
}
val config = applicationConfig.getFSConfig()
try {
config.config("fs")
} catch (e: ApplicationConfigurationException) {
logger.error(e) { "Tried to load a not-fs config!" }
exitProcess(WRONG_CONFIG)
}
//<...>
}
What IntelliJ does:
IntelliJ underlines the e: ApplicationConfigurationException
and shows the
following errors and documentations:
Error:
Type mismatch.
Required: Throwable
Found: ApplicationConfigurationException
Documentation:
public final class ApplicationConfigurationException
Thrown when an application is misconfigured
io.ktor.server.config 0_config.knm
Gradle: io.ktor:ktor-server-core:jvmAndNixMain:2.0.0 (io.ktor-ktor-server-core-jvmAndNixMain.klib)
The path to the source file, when I jump to the declaration of
ApplicationConfigException via IntelliJ is C:\Users\felix\.gradle\caches\modules-2\files-2.1\io.ktor\ktor-server-core\2.0.0\7064a323594c9b548ea52254325d1013f02da942\ktor-server-core-2.0.0-sources.jar!\jvmAndNixMain\io\ktor\server\config\ApplicationConfig.kt
.
(This path does not exist in the filesystem.)
===== Example 2 =====
My Code:
kotlin
val testApplication = TestApplication {
environment {
config = loadTestConfig("test_application.conf")
}
application {
environment.monitor.subscribe(FSInitialized) {
if (rootUser !in it.userManager)
it.userManager.put(rootUser)
if (adminUser !in it.userManager)
it.userManager.put(adminUser)
if (normalUser !in it.userManager)
it.userManager.put(normalUser)
}
fsServer.apply { main() }
}
}
The IDE marks environment.monitor.<...>
as error with the message Cannot
access 'environment': it is internal in 'TestApplicationBuilder'
.
The documentation of TestApplication
says:
@[ERROR : io.ktor.util.KtorDsl]
public fun TestApplication(
block: TestApplicationBuilder.() -> Unit
): TestApplication
Creates an instance of TestApplication configured with the builder block. Make sure to call TestApplication.stop after your tests.
See Also:
testApplication
io.ktor.server.testing 1_testing.knm
Gradle: io.ktor:ktor-server-test-host:jvmAndNixMain:2.0.0 (io.ktor-ktor-server-test-host-jvmAndNixMain.klib)
The documentation of application
says:
@[ERROR : io.ktor.util.KtorDsl]
public final fun application(
block: [ERROR : io.ktor.server.application.Application].() -> Unit
): Unit
Adds a module to TestApplication.
See Also:
testApplication
io.ktor.server.testing.TestApplicationBuilder
Gradle: io.ktor:ktor-server-test-host:jvmAndNixMain:2.0.0 (io.ktor-ktor-server-test-host-jvmAndNixMain.klib)
The declarations in the IDE are also pointing to some invalid paths.
===== Example 3 =====
Regardless to the errors in "Example 2" I can compile and run the Unit-Tests.
But then the code throws the following exception, when it reaches code from any
ktor package with a jvmAndNixMain-twin it throws a massive amount of exceptions.
(see example3_stacktrace.txt)
Module function cannot be found for the fully qualified name 'de.fs.web.PluginsKt.plugins'
io.ktor.server.engine.internal.ReloadingException: Module function cannot be found for the fully qualified name 'de.fs.web.PluginsKt.plugins'
at app//io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:27)
...
at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:46)
at de.fs.web.BasicTests$testBasicConfigDownload$1$invoke$lambda-1$$inlined$withConfiguredTestApplication$1.invokeSuspend(BasicTests.kt:681)
Caused by: io.ktor.server.engine.internal.ReloadingException: Module function cannot be found for the fully qualified name 'de.fs.web.PluginsKt.plugins'
at app//io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:27)
...
at app//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
===== Example 4 =====
When I check "Project -> External Libraries", the nixAndJvmMain-libs are loaded
from a different path than the other, normal working libs:
Normal:
Gradle: io.ktor:ktor-server-core-jvm:2.0.0
Classes:
C:\Users\felix\.gradle\caches\modules-2\files-2.1\io.ktor\ktor-server-core-jvm\2.0.0\2bf374bfde9bd8e96f7b3ed3ff85e3ccf11aa8b0\ktor-server-core-jvm-2.0.0.jar
Sources:
C:\Users\felix\.gradle\caches\modules-2\files-2.1\io.ktor\ktor-server-core-jvm\2.0.0\24cf9fccb8a1b7cff506364391b7263607880689\ktor-server-core-jvm-2.0.0.jar
Nix:
Gradle: io.ktor:ktor-server-core:jvmAndNixMain:2.0.0
Classes:
D:\git\firmensuche\.gradle\kotlin\sourceSetMetadata\search.firmensuche\jvmMain\implementation\io.ktor-ktor-server-core
Sources:
C:\Users\felix\.gradle\caches\modules-2\files-2.1\io.ktor\ktor-server-core-jvm\2.0.0\7064a323594c9b548ea52254325d1013f02da942\ktor-server-core-2.0.0-sources.jar
Like in "Example 1", the sources-path of the io.ktorktor server corejvmAndNixMain:2.0.0
doesn't exist.
So my guesses right now are:
A) The library is not correctly rersolved in IntelliJ/gradle and erroneously
loaded as dependency.
B) The jvmAndNixMain should not be loaded as library at all and the MPP-Plugin
has some serious issues with either modules and (only) ktor.
Right now we have a public holiday in germany, so I won't be able to respond do
any of your questions until tuesday. (Sorry for that!)Aleksei Tirman [JB]
04/18/2022, 9:09 AMzeugederunity
04/19/2022, 9:13 AMAleksei Tirman [JB]
04/19/2022, 9:31 AMzeugederunity
04/19/2022, 10:20 AMzeugederunity
04/19/2022, 10:51 AMAleksei Tirman [JB]
04/19/2022, 11:58 AMTest.kt: (36, 34): Unresolved reference: enviroment
because you mistyped the “enviro~*n*~ment” property. Is that correct?