Building a self-executable jar with Gradle and Kotlin

前端 未结 7 1442
囚心锁ツ
囚心锁ツ 2020-12-08 18:40

I\'ve written a simple kotlin source file in order to get started, and a gradle script file. But I can\'t figure out how to add the main func to the manifest, so that the ja

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 19:09

    If using Gradle with the Kotlin DSL, then my duplicate question has an answer of:

    import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
    import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
    
    plugins {
        kotlin("jvm") version "1.2.51"
        id("com.github.johnrengelman.shadow") version "2.0.4"
    }
    
    group = "xxx.yyy"
    version = "1.0-SNAPSHOT"
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation(kotlin("stdlib-jdk8"))
    }
    
    tasks.withType {
        kotlinOptions.jvmTarget = "1.8"
    }
    
    tasks.withType {
    
        manifest.attributes.apply {
            put("Implementation-Title", "Gradle Jar File Example")
            //put("Implementation-Version" version)
            put("Main-Class", "HelloKotlinWorld.App")
        }
    

    Which is, I think, the simplest solution. Oh, perhaps you're using just Kotlin itself and not the DSL.

提交回复
热议问题