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

Sebastien Leclerc Lavallee

03/11/2020, 3:49 PM
Hello there! I have a kotlin multiplatform sub-project that I want as an application. I did enable the
application
plugin and when I
installDist
, everything seems to work as expected. I see my app in the build dir and the associated jar file. The problem is when I run the app, I have an error saying it can’t find the main class I did specifiy in my build.gradle. When checking my jar file, it is totally empty. There is only the
MANIFEST.MF
. Most of my classes are in the commonMain sourceset and some actual in the jvmMain sourceset. Anyone has encountered this ? Any things to check? Thanks 🙂
f

fkrauthan

03/11/2020, 6:49 PM
I think the application plugin is not compatible with the kotlin multiplatform as it has trouble finding sources in a common package.
s

Sebastien Leclerc Lavallee

03/11/2020, 7:03 PM
I don’t think that’s my problem. I did remove the application plugin but if I do
./gradlew build
I still get an empty jar file for this subproject. From what I see… out of my 3 subprojects, only 1 produce a jar file with something in it but they all have a jvm sourceset
l

Luoqiaoyou

03/12/2020, 2:21 AM
can u post ur gradle configuration. im developing a mpp lib ,everything is fine in jvm/android
s

Sebastien Leclerc Lavallee

03/12/2020, 2:31 AM
Copy code
@@ -1,198 +0,0 @@
import org.jetbrains.kotlin.gradle.plugin.*

buildscript {
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
    }
}

plugins {
    id "org.jetbrains.kotlin.plugin.serialization"
}

apply plugin: "org.jetbrains.kotlin.multiplatform"
apply plugin: 'kotlinx-serialization'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'

kotlin {
    jvm()

    sourceSets {
        commonMain {
            dependencies {
                implementation project(":runtime")
                implementation kotlin("stdlib-common")
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialization_version"
            }

            archivesBaseName = "protoc-gen-kotlin-common"
            publishSettings(project, archivesBaseName, "Common library for pbandk protobuf code generator")
        }
        commonTest {
            dependencies {
                implementation kotlin("test-common")
                implementation kotlin("test-annotations-common")
            }
        }

        jvmMain {
            application {
                mainClassName = "pbandk.gen.MainKt"
                applicationName = "protoc-gen-kotlin"
            }

            dependencies {
                implementation kotlin("stdlib")
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialization_version"
                implementation "com.google.protobuf:protobuf-java:$protobuf_version"
            }

            sourceCompatibility = "1.8"
            tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
                kotlinOptions {
                    jvmTarget = "1.8"
                }
            }

            jar {
                enabled = true
            }
            bootJar {
                launchScript()
            }

            configurations.archives.artifacts.removeIf { it.name ==~ /.*-boot/ && it.type ==~ /zip|tar/ }
            artifacts {
                archives bootJar
            }

            archivesBaseName = 'protoc-gen-kotlin'
            publishSettings(project, archivesBaseName, 'JVM library for pbandk protobuf code generator')
        }
        jvmTest {
            dependencies {
                implementation kotlin("test")
                implementation kotlin("test-junit")
                implementation "junit:junit:4.12"
            }
        }

        /*
        macosMain {
        }
        macosTest {
        }
        */
    }
}
25 Views