Spring Boot 2.5.0 generates plain.jar file. Can I remove it?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Spring Boot 2.5.0 and Plain JAR File Generation
Spring Boot is a powerful framework that simplifies the configuration and deployment of Java applications by offering a variety of features designed to be lightweight and productive. Spring Boot 2.5.0, a notable release in the framework's path, introduced several changes that improved its usability, performance, and integration with other technologies. Among these changes is the generation of a plain.jar file, which can sometimes confuse developers. This article explains why this file is generated, its purpose, and whether it can be safely removed.
Introduction to Spring Boot JARs
When you build a Spring Boot application, the result is typically an executable JAR file that contains all the necessary dependencies, resources, and classes. This approach allows you to run your application by simply executing the JAR file without needing external dependencies.
The Role of plain.jar
With Spring Boot 2.5.0, in some build setups, such as when using Gradle, you may notice the creation of a plain.jar file alongside your main executable JAR file. The purpose of this plain.jar is typically to include only the application classes and resources, excluding its dependencies. This file might be used in specific deployment scenarios or environments where dependencies are managed separately, or for tasks such as testing and modularization deployment strategies.
Key Characteristics of plain.jar
- Excludes Dependencies: Unlike the executable JAR, it doesn't package the libraries; it includes only the compiled code and resources of your application.
- Deployment Flexibility: Useful in environments where libraries are provided by a container or another build tool, reducing redundancy and potentially saving storage.
- Testing and Customization: It may assist in scenarios such as continuous integration pipelines where you want to execute integration tests against a dynamically constructed classpath.
Can You Remove plain.jar?
If your deployment environment does not require anything other than the main executable JAR file, it is typically safe to remove the plain.jar. Before deciding to do so, consider the following:
- Build and Deploy Scripts: Check your build and deployment scripts to ensure they don’t reference the
plain.jar. - Continuous Integration Systems: Verify that any automation doesn’t rely on the presence of this file for testing or deployment.
- Understand Your Environment: Ensure your deployment environment doesn't necessitate a
plain.jarin its operation, particularly in custom or enterprise environments where modular deployment strategies may be employed.
Managing plain.jar Generation
In a Gradle build setup with Spring Boot, controlling the generation of plain.jar can be managed by adjusting build configurations. Here's an example on how to modify your build script to prevent unwanted outputs:
bootJar Task: This task creates the executable Spring Boot JAR. Ensuring it is enabled means you'll always have the complete package.jar Task: Disabling this task means aplain.jarwill not be produced by default.
Conclusion
While the plain.jar file can play a useful role in specific deployment or testing setups, it is often unnecessary for traditional Spring Boot applications intended to run as standalone executables. Understanding your project's deployment needs and build configuration will guide you in determining whether it is needed.
Summary Table
| Aspect | Details |
Purpose of plain.jar | Contains only application classes and resources without dependencies. |
| Can be removed? | Yes, if not required for your deployment or testing. |
| Controlled by | Gradle build tasks (bootJar, jar). |
| Default behavior | When rules are unchanged, both executable and plain.jar might be generated. |
| Use cases | Testing, modular deployment, environments managing their own dependencies. |
By understanding these aspects, you can optimize your Spring Boot application builds, ensuring that only the necessary components are generated and deployed, reducing complexity and improving build efficiency.

