Hi! I have a multiplatform module containing a ser...
# multiplatform
p
Hi! I have a multiplatform module containing a server, with one kotlin multiplatform dependency module . Running it from main function with play button produces following error:
Error: Could not find or load main class com.well.server.ApplicationKt
I’ve found a solution to run it, using following task:
task<JavaExec>("run") {
main = "com.well.server.ApplicationKt"
val jvm by kotlin.targets.getting
val main: KotlinCompilation<KotlinCommonOptions> by jvm.compilations
val runtimeDependencies = (main as KotlinCompilationToRunnableFiles<KotlinCommonOptions>).runtimeDependencyFiles
classpath = files(main.output.allOutputs, runtimeDependencies)
}
One of the minuses - I can’t debug server and run an other module, because server starts running as part of task, and task progress remains 92 until I abort it. Is there a better solution? But the main goal right now is to deploy the server. Following the official guide, I tried this code:
tasks.create("stage") {
dependsOn(tasks.getByName("installDist"))
}
application {
mainClassName = "ApplicationKt"
}
distributions {
main {
contents {
from("$buildDir/libs") {
rename("${rootProject.name}-jvm", rootProject.name)
into("lib")
}
}
}
}
tasks.getByName<JavaExec>("run") {
`classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by
jvmJar
can be found and served`
}
But
./gradlew :server:run
returns
Could not find or load main class ApplicationKt
error, and
:server:jvmJar
finishes without errors but doesn’t seems to produce the output
b
Can you send us your main function? Play button should work!
p
b
Looks like IDEA is not picking up your custom resources folder. Can you try moving it to
src/jvmMain/resources
?
p
done, but result is the same error🤔
b
Aaaaaah! I remember having the same. I know what's up 😄
In
build.gradle.kts
add
withJava()
in
kotlin { jvm {} }
Then you'll be able to run it with both,
./gradlew run
and play button
p
tried it too, still `Could not find or load main class`😞
b
Damn!
Ok, managed to get
./gradlew run
working by adding
Copy code
application {
    mainClassName = "io.ktor.server.netty.EngineMain"
}
to gradlefile
With the above, this also works for me
p
what have you changed in the config? I see no difference with a default one, and it still doesn’t work for me. have you changed main class? I tried specifying
io.ktor.server.netty.EngineMain
in the config, and it says
Neither port nor sslPort specified
. yet running
./gradlew run
indeed works
b
Did you make sure to select correct module in Run Configuration dialog?
i.e. jvmMain?
I've also had issues importing the project into INTELLIJ due to android versions, so I've commented out
//include(":app")
in
settings.gradle.kts
p
Jesus, it’s really related to android module somehow😱 I’ve pushed fix so you can build it in INTELLIJ without disabling the app module..
b
Works fine for me now
Add me as contributor to that repo (mpetuska) an I'll raise a PR on what's different on my end
Unless it works for you too
p
have you run sync after un-committing
app
? I just tried on your commit and it works only with the committed
app
module.
b
i did
b
Try re-importing it to intellij? i.e. remove .idea and go through import from existing sources again
Or just plain opening
a
build.gradle.kts
Copy code
plugins {
  kotlin("multiplatform")
  id("tz.co.asoft.application") version "0.0.7"
}

konfig {
  debug(
    "Main-Class" to "io.ktor.server.netty.EngineMain"
  )
}
after that you can just run
./gradlew jvmRunDebug
p
I tried cleaning .idea and build folders, as well as cloning repo from scratch, still
Could not find or load main class
if android module is enabled, and works if disabled.. also even if it works(without android module), running executable created with
:distZip
fails with
Neither port nor sslPort specified
.. tried specifying port as a param, it says
No configuration setting found for key 'ktor'
Why can it ignore
application.conf
?
@andylamax thanks, lib looks pretty interesting, I’ll check it out later, but for now I’d like to run project without extra dependencies.
a
You don't have to add any dependencies if you are not using the konfigs. Only the gradle plugin to run the application
b
I'm on eap intellij. Maybe try upgrading your idea and make sure to run gradle commands via wrapper?
Also, try clearing your maven and gradle caches
p
ok, it works on EAP😁 any idea how to fix the distribution? running executable created with 
:distZip
  fails with 
Neither port nor sslPort specified
 .. tried specifying port as a param, it says  
No configuration setting found for key 'ktor'
  Why can it ignore 
application.conf
?
b
No clue never used that. Try applying shadow plugin to get fat jar instead
👍 1
p
Thanks for help, man!
b
Np, glad you got this sorted