What does "build once, deploy many" mean?
IntermediateConceptJava builds (Maven, Gradle, JAR, WAR)
Answer
Short answer
You build the artifact (JAR, image) one time, test it, and then promote that exact same artifact through dev → staging → production, changing only configuration (env vars, ConfigMaps, secrets). You never rebuild for each environment.
Why it matters
- What you tested in staging is byte-for-byte what runs in production.
- Rebuilding per environment can pull different dependency versions, base images or compiler output — "it passed in staging" stops meaning anything.
- Rollback is trivial: redeploy the previous artifact version.
How it looks
commit 9f2c1ab → CI builds orders:1.4.0-9f2c1ab → push to registry
dev: deploy orders:1.4.0-9f2c1ab + dev config
staging: deploy orders:1.4.0-9f2c1ab + staging config
prod: deploy orders:1.4.0-9f2c1ab + prod config
Even better, deploy by image digest (orders@sha256:...) so the tag can't be moved.
What it requires
Configuration must be external to the artifact — no environment URLs or secrets baked into the JAR or image.
What to say in the interview
"Build once, deploy many means a single immutable artifact promoted across environments with only external config changing. It guarantees we deploy what we tested and makes rollbacks simple; we often pin deployments to the image digest."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR
More on Java builds (Maven, Gradle, JAR, WAR)
What is pom.xml and what is it used for?BeginnerHow do you build and run a Java project with Maven?BeginnerWhat is the difference between a JAR and a WAR file?BeginnerWhat is Gradle and how is it different from Maven?BeginnerHow do you configure a Spring Boot application for different environments?BeginnerA Maven build fails in the pipeline with "Could not resolve dependencies". How do you fix it?Intermediate