And to go along with this. Is there any way to app...
# multiplatform
f
And to go along with this. Is there any way to apply the application plugin together with the kotlin multiplatform plugin?
s
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
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
@Big Chungus do you have any sample?
b
I do, will post it tomorrow once i get to my pc
f
Perfect thank you
b
@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
Cool that works :)
s
I add this at the end of the build.gradle ?
f
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
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
Just do
./gradlew jvmRun
It will not produce jar, but rather compile project and run it directly
s
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
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
I need to have something self contained. That why the jar file.