🌑

帮帮技术站

gradle项目建立fatJar包

  1. Idea新建项目

  2. 配置task,把依赖包都打进最终包中

1
2
3
4
5
6
7
8
9
10
11
12
13
//FAT jar

tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes("Main-Class" to "com.bbbang.key.MainKt")
}
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}


  1. 全部build.gradle.kts配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    import org.gradle.jvm.tasks.Jar
    import java.util.jar.Manifest

    plugins {
    kotlin("jvm") version "1.8.0"
    application
    }

    group = "com.bbbang.info"
    version = "1.0.0"

    repositories {
    mavenLocal()
    mavenCentral()
    }

    dependencies {
    testImplementation(kotlin("test"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.0")
    implementation("com.github.oshi:oshi-core:6.4.2")
    implementation("ch.qos.logback:logback-classic:1.4.7")
    }

    tasks.test {
    useJUnitPlatform()
    }

    kotlin {
    jvmToolchain(11)
    }

    application {
    mainClass.set("com.bbbang.key.MainKt")
    }

    //FAT jar

    tasks.withType<Jar> {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
    attributes("Main-Class" to "com.bbbang.key.MainKt")
    }
    configurations["compileClasspath"].forEach { file: File ->
    from(zipTree(file.absoluteFile))
    }
    }

, , — Jun 23, 2023

Search