Howto setup kotlin gradle plugin to work with embedded linux jvm

I use Kotlin to write an application for Embedded Linux (Raspberry).
I use the “Embedded Linux JVM” Plugin to distribute my project.
With an old “idea” project configuration things worked as expected.
I recently switched to gradle kts, but now the project will not run after deployment due to missing classes.
I noticed that the old project setup has a folder called ‘lib’ with jars that are obviously copied to a ‘lib’ folder on the Raspi.
The new project has no ‘lib’ folder in the IDE and there are far less jars copied to the target although both projects have the same “External libraries”.

Here is my gradle.kts

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.4.10"

group = ""
version = "1.0-SNAPSHOT"

repositories {

dependencies {
    implementation("io.github.microutils", "kotlin-logging-jvm", "2.0.3")
    implementation("org.apache.logging.log4j", "log4j-slf4j-impl", "2.13.0")

I don’t see anything about the embedded jvm here. Could you share the idea config that works?

The problem is that kotlin-logging-1.12.0.jar (and a lot of others jars) are not copied to the Raspi.
If I copy them manually, everything works.
In fact only the following jars are copied:

  • access-bridge-64.jar
  • annotations-13.0.jar
  • annotations-16.0.1.jar
  • apiguardian-api-1.0.0.jar
  • charsets.jar
  • cldrdata.jar
  • commons-collections4-4.1.jar
  • deploy.jar
  • dnsns.jar
  • jaccess.jar

Running the application locally (on Windows) also works, so the project is ok.
I guess the plugin is taking libraries from a location that does not conform to the project layout of the new default gradle setup (the one you get when creating a project with NewProjectGradleKotlin/JVM).

This is the IDEA project XML

<component name="ArtifactManager">
  <artifact type="jar" name="OCR:jar">
    <root id="archive" name="OCR.jar">
      <element id="module-output" name="OCR" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/kotlin-stdlib-1.4.0.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/annotations-13.0.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/kotlin-stdlib-common-1.4.0.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/junit-jupiter-api-5.4.2.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/apiguardian-api-1.0.0.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/opentest4j-1.1.1.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/junit-platform-commons-1.4.2.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-test.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk7.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk8.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/jsr305-3.0.2.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/annotations-16.0.1.jar" path-in-jar="/" />
      <element id="extracted-dir" path="$PROJECT_DIR$/lib/slf4j-api-1.7.25.jar" path-in-jar="/" />
      <element id="library" level="project" name="org.apache.logging.log4j:log4j-slf4j-impl:2.13.0" />
      <element id="library" level="project" name="org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9" />
      <element id="library" level="project" name="io.github.microutils:kotlin-logging-jvm:2.0.3" />

With gradle there is no “lib” everything is in build…how do you run it? Also you are missing the coroutines dependency. You may want to have a look at the “application” gradle plugin as well as it allows you to package your program easily.

1 Like

I verified that everything is correct with the project and all dependencies are resolved. I guess the plugin just doesn’t work well with gradle dependencies.
Well it’s ok for me at the moment to copy the jars manually since they don’t change very often.

I had similar problem with Kotlin and Embedded Linux JVM. My solution was:

Go to Project Structure > Modules > (Submodules) > Dependencies.
(e.g. in my case Kotlin Standard Library was in module: iotapp.main, and this is the module you have to specify in Run/Debug Configuration of Embedded Linux JVM plugin)

Go to Run > Edit Configurations > Embedded Linux JVM > (your run name) > Module: > and specify the name of module in which you have found these libraries (e.g. in my case iotapp.main).

Also, for the Main Class: pay attention - e.g. Hello.kt without class defined (but only main method), the main class will be autogenerated in HelloKt.class (so for the main class you specify HelloKt, not Hello).