https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
p

Philip Dukhov

11/18/2020, 10:24 PM
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

Big Chungus

11/19/2020, 9:30 AM
Can you send us your main function? Play button should work!
p

Philip Dukhov

11/19/2020, 2:09 PM
b

Big Chungus

11/19/2020, 2:12 PM
Looks like IDEA is not picking up your custom resources folder. Can you try moving it to
src/jvmMain/resources
?
p

Philip Dukhov

11/19/2020, 2:29 PM
done, but result is the same error🤔
b

Big Chungus

11/19/2020, 2:31 PM
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

Philip Dukhov

11/19/2020, 2:43 PM
tried it too, still `Could not find or load main class`😞
b

Big Chungus

11/19/2020, 2:44 PM
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

Philip Dukhov

11/19/2020, 3:15 PM
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

Big Chungus

11/19/2020, 3:32 PM
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

Philip Dukhov

11/19/2020, 3:51 PM
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

Big Chungus

11/19/2020, 3:55 PM
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

Philip Dukhov

11/19/2020, 4:23 PM
have you run sync after un-committing
app
? I just tried on your commit and it works only with the committed
app
module.
b

Big Chungus

11/19/2020, 4:45 PM
i did
b

Big Chungus

11/19/2020, 4:47 PM
Try re-importing it to intellij? i.e. remove .idea and go through import from existing sources again
Or just plain opening
a

andylamax

11/19/2020, 4:50 PM
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

Philip Dukhov

11/19/2020, 5:33 PM
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

andylamax

11/19/2020, 6:06 PM
You don't have to add any dependencies if you are not using the konfigs. Only the gradle plugin to run the application
b

Big Chungus

11/19/2020, 6:33 PM
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

Philip Dukhov

11/20/2020, 8:11 AM
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

Big Chungus

11/20/2020, 8:55 AM
No clue never used that. Try applying shadow plugin to get fat jar instead
👍 1
p

Philip Dukhov

11/20/2020, 11:27 AM
Thanks for help, man!
b

Big Chungus

11/20/2020, 1:52 PM
Np, glad you got this sorted
3 Views