Spring Boot 2.5.0 generates plain.jar file. Can I remove it?

We Are Going To Discuss About Spring Boot 2.5.0 generates plain.jar file. Can I remove it?. So lets Start this Java Article.

Spring Boot 2.5.0 generates plain.jar file. Can I remove it?

  1. Spring Boot 2.5.0 generates plain.jar file. Can I remove it?

    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.

  2. Spring Boot 2.5.0 generates plain.jar file. Can I remove it?

    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.

Solution 1

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.

Original Author edited May 24, 2021 at 23:34 Of This Content

Solution 2

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:

Original Author Of This Content

Solution 3

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("")
}

Original Author Of This Content

Solution 4

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.

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment