SpringBoot2.5.0生成 plain.jar 文件。我可以删除它吗?

在 SpringBoot2.5.0更新之后,它将生成与通常的 myprogram-0.0.1.jar一起的 myprogram-0.0.1-plain.jar文件。我是否可以禁止 gradle 生成 *.plain.jar文件?我使用的是第7.0级。

我得到的是:

build/
libs/
myprogram-0.0.1.jar
myprogram-0.0.1-plain.jar

我想要的:

build/
libs/
myprogram-0.0.1.jar

打造:

plugins {
id 'org.springframework.boot' version '2.5.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}


group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'


repositories {
mavenCentral()
}


dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}


test {
useJUnitPlatform()
}


41036 次浏览

It was a change in Spring Boot 2.5.0.

As @ThomasKläger pointed out: You can set it in the build.gradle configuration.

build.gradle

jar {
enabled = false
}

For Kotlin devs:

tasks.getByName<Jar>("jar") {
enabled = false
}

Alternatively, you can run the bootJar task. It produces only the default runnable jar.

Try use follow setting:

jar {
enabled = true
archiveClassifier = '' //use empty string
}

Because org.springframework.boot.gradle.plugin.JavaPluginAction.java

private void classifyJarTask(Project project) {
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class)
.configure((task) -> task.getArchiveClassifier().convention("plain"));
}

From spring-boot-gradle-plugin sources file:

See:

This gradle config will produce myprogram-0.0.1.jar instead of myprogram-0.0.1-plain.jar

In your build.gradle.kts

// Build executable jar
tasks.jar {
enabled = true
// Remove `plain` postfix from jar file name
archiveClassifier.set("")
}

Instead of using the build gradle task you could use bootJar. That will only build the bootable jar.

Keep in mind that bootJar won't run your tests before building.

Tested solution. I was facing the same issue: just add below in your gradle

jar{
archiveClassifier=''
enabled = false
}