Operations 14 min read

Splitting Dependencies and Optimizing Jenkins Builds for Spring Boot Projects with Docker Integration

This guide explains how to reduce Spring Boot jar size by separating third‑party dependencies from business code, configure Maven for dependency splitting, use Jenkins to detect changes via MD5 checks, and deploy the resulting packages through SSH or Docker‑based pipelines.

IT Services Circle
IT Services Circle
IT Services Circle
Splitting Dependencies and Optimizing Jenkins Builds for Spring Boot Projects with Docker Integration

Spring Boot projects often produce large executable JARs because all third‑party dependencies are packaged together, resulting in files of tens of megabytes even when the business code is only a few kilobytes.

To address this, the article shows how to split dependencies by adding a pom.xml configuration that uses the maven-dependency-plugin and the Spring Boot Maven plugin to place external libraries into a separate lib directory while keeping the application JAR small (e.g., ~157 KB).

After rebuilding with mvn clean package -DskipTests=true, the target/lib folder contains all dependency JARs, and the application can be launched with java -Dloader.path=./lib -jar xxx.jar, allowing incremental updates: only the small business JAR needs to be uploaded when code changes, saving bandwidth and time.

Because managing the split packages adds complexity, a Jenkins pipeline is introduced to automate the process. The pipeline runs a local script jenkins_jar_and_lib_check.sh that creates a temporary directory, copies the built JARs, and performs MD5 verification using the functions jar_check_md5 and jar_unzip_check_md5. Unchanged JARs are removed locally to avoid unnecessary transfer.

For SSH deployment, the script jenkins_restart_mini.sh checks whether any dependency or business JAR has changed, determines if the service process is running, and restarts the application only when needed.

The article also presents a Docker‑based approach. By building two images—one for the immutable dependencies ( lib-jenkins-mini-build) and one for the application ( app) that inherits from the dependency image—teams can push updated images to a registry and restart containers with docker-compose. Dockerfiles for both images are provided, and the helper script docker-image-build.sh performs the same MD5 checks to decide whether to rebuild the dependency or application image.

Overall, the solution combines Maven configuration, Jenkins automation, MD5‑based change detection, and optional Docker packaging to dramatically reduce deployment size and time while maintaining reliable CI/CD workflows.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerci/cddependency managementmavenSpringBootJenkinsshell script
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.