Reputation: 4440
After the Spring Boot 2.5.0 update, it generates the myprogram-0.0.1-plain.jar
file alongside the usual myprogram-0.0.1.jar
. Can I disallow gradle to generate the *.plain.jar
file? I use Gradle 7.0.2.
What I get:
build/
libs/
myprogram-0.0.1.jar
myprogram-0.0.1-plain.jar
What I want:
build/
libs/
myprogram-0.0.1.jar
build.gradle:
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()
}
Upvotes: 145
Views: 77984
Reputation: 606
If you want to use gradle build
command with build.gradle.kts
, the settings should be like this:
tasks.jar {
enabled = false
}
tasks.bootJar {
archiveBaseName.set("myname")
archiveVersion.set("")
}
//OR
tasks.bootJar {
archiveFileName = "myname.jar"
}
This will only create a bootable jar.
Upvotes: 0
Reputation: 21
If you are using springboot, you can disable generation of **--plain.jar by adding below code to your gradle file.
jar {
// disable generation of **--plain.jar
enabled = false
archiveFileName = bootJar.archiveFileName
}
Upvotes: 2
Reputation: 1
I had the same problem today!
above springboot 2.5, use jar or war build project will append plain text to the name of target file
task.getArchiveClassifier().convention("plain")
so you can define this to resolve this problem
jar {
classifier = ''
}
yeah, you can see that the author tell you how to config it in this url https://github.com/spring-projects/spring-boot/commit/ebdb046ca93684b45691e689b6a23562dd636b61#diff-5efe17833c4d5e21d01178734dea8859dc1669199669101a36448ed696413820.
Upvotes: -1
Reputation: 86
Tested solution. I was facing the same issue: just add below in your gradle
jar{
archiveClassifier=''
enabled = false
}
Upvotes: 6
Reputation: 479
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:
Upvotes: 47
Reputation: 2506
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.
Upvotes: 4
Reputation: 523
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("")
}
Upvotes: 14
Reputation: 4440
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.
Upvotes: 162