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

fkrauthan

03/10/2020, 7:17 PM
And to go along with this. Is there any way to apply the application plugin together with the kotlin multiplatform plugin?
s

Sebastien Leclerc Lavallee

03/10/2020, 7:23 PM
I just did that and seems to work:
Copy code
plugins {
    id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
    id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
}

apply plugin: 'kotlinx-serialization'
apply plugin: 'application'
🤔 Might not be that simiple. I’m currently moving to the new MPP plugin. I just did add the
application
plugin, generate the application but when executing, can’t find main class
b

Big Chungus

03/10/2020, 7:50 PM
Just create custom Jar and JvmExec tasks and add your runtime classpaths. For Jar also configure main class in manifest. Goohle around on that and let me know if you still cannot figure it out
f

fkrauthan

03/10/2020, 8:40 PM
@Big Chungus do you have any sample?
b

Big Chungus

03/10/2020, 9:13 PM
I do, will post it tomorrow once i get to my pc
f

fkrauthan

03/10/2020, 9:16 PM
Perfect thank you
b

Big Chungus

03/11/2020, 8:42 PM
@fkrauthan, there you go:
Copy code
afterEvaluate {
  tasks {
    val compileKotlinJvm by getting(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class)
    val jvmProcessResources by getting(Copy::class)
    val jvmRun by creating(JavaExec::class) {
      dependsOn(compileKotlinJvm, jvmProcessResources)
      group = "run"
      main = "lt.petuska.IndexKt"
      classpath = configurations["jvmRuntimeClasspath"] + compileKotlinJvm.outputs.files +
          jvmProcessResources.outputs.files
      workingDir = buildDir
    }
    val jvmJar by getting(Jar::class) {
      manifest {
        attributes["Main-Class"] = jvmRun.main
        attributes["Version"] = project.version
      }
    }
  }
}
f

fkrauthan

03/11/2020, 9:11 PM
Cool that works :)
s

Sebastien Leclerc Lavallee

03/11/2020, 9:54 PM
I add this at the end of the build.gradle ?
f

fkrauthan

03/11/2020, 10:02 PM
Yeah. In addition to that I personally added
Copy code
args = System.getProperty("exec.args", "").split(" ")
To the jvmRun command. This way I can use
-Dexec.args=""
to pass along command line arguments (not perfect but will do for some testing in my case)
and I did add
Copy code
from(kotlin.jvm().compilations.getByName("main").compileDependencyFiles.map { if (it.isDirectory) it else zipTree(it) })
to the
jvmJar
command to pack dependencies into my fat jar
s

Sebastien Leclerc Lavallee

03/11/2020, 10:04 PM
Thanks, I’ll test these out later
Is it possible to do this in groovy gradle?
I did change to use a
.kts
file, I did run task
jvmJar
and the jar is produced. Now how can I use that jar file with the script? Thanks 🙂
b

Big Chungus

03/12/2020, 2:25 PM
Just do
./gradlew jvmRun
It will not produce jar, but rather compile project and run it directly
s

Sebastien Leclerc Lavallee

03/12/2020, 2:56 PM
What I need is to use that jar file from another app. I’m creating a
protoc
plugin… I did manage to manualy change the
.sh
file generated from the gradle application plugin. Fingers crossed 🤞 kotlin multiplatform and application plugins will be working in the future
b

Big Chungus

03/12/2020, 2:59 PM
Why not just have another jvmRun task like the one in my example that extends the classpath with the classpath of child project?
or just add zipTree of that jar
s

Sebastien Leclerc Lavallee

03/12/2020, 3:43 PM
I need to have something self contained. That why the jar file.