gradle - 在Gradle 5 Kotlin DSL中构建项目后如何重命名文件

标签 gradle gradle-kotlin-dsl

您能否帮助我找到使用Gradle 5 Kotlin DSL重命名内置 Artifact 的正确方法

我创建了一个基于Kotlin DSL的Gradle 5.5.1 Spring Boot 2项目。

执行gradle build之后,构建的 Artifact 在$ buildDir / libs文件夹中。

如何重命名?假设我想给一个简单的名字-app.jar


plugins {
    id("java")
    id("idea")
    id("org.springframework.boot") version "2.1.5.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
}

group = "com.hbv"
version = "1.0.0-SNAPSHOT"

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.5.RELEASE")
    }
}

the<DependencyManagementExtension>().apply {
    imports {
        mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

repositories {
    mavenLocal()
    mavenCentral()
}


dependencies {
    implementation(platform("org.springframework.cloud:spring-cloud-dependencies:Greenwich.RELEASE"))

    implementation("org.springframework.cloud:spring-cloud-starter-config")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("org.springframework.boot:spring-boot-starter-security")

    testImplementation("com.h2database", "h2")
    testImplementation("org.springframework.boot", "spring-boot-starter-test")
    testImplementation("org.springframework.security", "spring-security-test")

}```

最佳答案

配置生成jar的the bootJar task并成为gradle jar task并设置其 archiveFileName property:

tasks {
    bootJar {
        archiveFileName.set("app.jar")
    }
}

关于gradle - 在Gradle 5 Kotlin DSL中构建项目后如何重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57236042/

相关文章:

java - 列出 JAR 中的资源文件

eclipse - 如何使用Gradle Kotlin DSL创建Eclipse项目?

java - 将文件添加到Kotlin DSL中的Gradle sourceSets

gradle - Gradle Kotlin DSL 无法识别 buildscript 中的 ext

java - 将Gradle-Kotlin构建转换为Maven?

java - 使用 Gradle 构建时出错 : Cause: error=2, 没有这样的文件或目录

Android Gradle 项目升级构建工具到 21.0.1 : aapt throws Exception

gradle - 向Android Studio添加android批注的步骤

windows - Gradle命令行启动错误

gradle - Flyway 和 gradle kotlin dsl