Home > Net >  How can I find the main class of my app when selecting it to create a JAR ? Kotlin
How can I find the main class of my app when selecting it to create a JAR ? Kotlin

Time:12-28

I want to make a JAR to test and deploy my app but it doesn't work, locally it can't find the main attribute in the manifest file, and in the deployement it starts but i have this error :

java.lang.noclassdeffounderror: kotlinx/coroutines/slf4j/mdccontex
W

hen I do it locally using the artifact Jar I can't find the MainClass of my app, it recommands me all sorts of other modules.

I tried modying my gradle, the manifest, the configuration but really nothing works it's depressing, it looks so easy on some youtube videos but it just doesn't work what I do to make the JAR

The classes i have access to when i try to select them Here is my Gradle

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

plugins {
    kotlin("jvm") version "1.5.10"
    application
    kotlin("plugin.serialization") version "1.6.10"
}

version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
    maven(url = "https://jitpack.io")
}

val ktor_version: String by project

dependencies {
    // Fix HTML issue on some responses
    implementation("org.apache.commons:commons-text:1.10.0")
    // Ktor dependencies
    implementation("io.ktor:ktor-client-auth:$ktor_version")
    implementation("io.ktor:ktor-client-core:$ktor_version")
    implementation("io.ktor:ktor-client-cio:$ktor_version")
    implementation("io.ktor:ktor-client-resources:$ktor_version")
    implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
    implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
    implementation("io.ktor:ktor-client-logging:$ktor_version")
    // Logging dependencies
    implementation("ch.qos.logback:logback-classic:1.4.0")
    implementation(kotlin("stdlib-jdk8"))
    // Database
    implementation ("mysql:mysql-connector-java:8.0.30")
    implementation ("org.ktorm:ktorm-core:3.5.0")
    implementation ("org.ktorm:ktorm-support-mysql:3.5.0")
}

application {
    mainClass.set("MainKt")
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
    jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
    jvmTarget = "1.8"
}
tasks {
    jar {
        manifest {
            attributes["Main-Class"] = application.mainClass
        }
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE

        configurations.compileClasspath.get().forEach {
            from(if (it.isDirectory) it else zipTree(it))
        }
    }
    compileKotlin{
        kotlinOptions.jvmTarget = "1.8"
    }


}

Thanks in advance

CodePudding user response:

My project had a lot of issues and inconsistency so I started a new one and copied all the files / packages, spent an hour redoing all the imports and plugins that my code actually needed to run and it finally worked, the same comments don't work on the previous project

  • Related