How to create the fat jar with gradle kotlin script

前端 未结 3 1840
南方客
南方客 2020-12-24 01:31

As titled, I\'d like to know how to modify the gradle.build.kts in order to have a task to create a unique jar with all the dependencies (kotlin li

3条回答
  •  执念已碎
    2020-12-24 01:53

    You could use the ShadowJar plugin to build a fat jar:

    import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
    
    buildscript {
        repositories {
            mavenCentral()
            gradleScriptKotlin()
        }
        dependencies {
            classpath(kotlinModule("gradle-plugin"))
            classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
        }
    }
    
    apply {
        plugin("kotlin")
        plugin("com.github.johnrengelman.shadow")
    }
    
    repositories {
        mavenCentral()
    }
    
    val shadowJar: ShadowJar by tasks
    shadowJar.apply {
        manifest.attributes.apply {
            put("Implementation-Title", "Gradle Jar File Example")
            put("Implementation-Version" version)
            put("Main-Class", "com.mkyong.DateUtils")
        }
    
        baseName = project.name + "-all"
    }
    

    Simply run the task with 'shadowJar'.

    NOTE: This assumes you're using GSK 0.7.0 (latest as of 02/13/2017).

提交回复
热议问题