如何让 Gradle jar 任务输出由 bootJar 生成的相同存档

问题描述 投票:0回答:0

我有一个基于 Gradle 的 SpringBoot

2.7.9
应用程序,当我执行
./gradlew jar
它会产生:

/Users/user/git/repo/build/libs/repo-0.1.0-SNAPSHOT-plain.jar

这是不可执行的。

我真的希望

jar
的输出与执行
bootJar
时生成的输出相同。

运行

gradlew bootJar
,生成
repo-0.11.0-SNAPSHOT.jar
,可执行

我需要继续使用

./gradlew jar
.

plugins {
    java
    id("org.springframework.boot")
}

val gitBuildURL: String by project
val gitBranchName: String by project
val gitCommit: String by project

dependencies {
    implementation("org.springframework.boot:spring-boot-starter:2.7.9")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.7.9")
    implementation("org.liquibase:liquibase-core:4.20.0")
    implementation("org.postgresql:postgresql:42.6.0")
    testImplementation("org.springframework.boot:spring-boot-starter-test:2.7.9")
}

publishing {
    publications {
        create<MavenPublication>("springLib") {
            from(components["java"])
            versionMapping {
                usage("java-api") {
                    fromResolutionOf("runtimeClasspath")
                }
                usage("java-runtime") {
                    fromResolutionResult()
                }
            }
        }
    }
}

artifactory {
    publish {
        defaults{
            publications("springLib")
            setProperties(mapOf(
                "git.build.url" to gitBuildURL,
                "git.branch.name" to gitBranchName,
                "git.commit.id" to gitCommit
            ))
        }
    }
}

spring-boot gradle jar build.gradle executable-jar
© www.soinside.com 2019 - 2024. All rights reserved.