Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

A service uses Maven profiles dev, qa and prod to package different configuration files into the jar. What are the drawbacks and what would you recommend instead?

Packaging different configuration per environment means we build a different jar for each environment, so the artifact tested in qa is not the one deployed to prod, and secrets can end up baked into jars. Instead, we build once and promote the same artifact through every environment, supplying environment settings at runtime with Spring profiles, environment variables or a config service. Maven profiles stay for build concerns such as slow tests, native builds or release signing.

Why this question is asked

Using Maven profiles for environments is one of the most common patterns in older Java projects, and it seems natural: dev, qa and prod need different database URLs, so we build them differently. The problem shows up later, when a prod-only bug cannot be reproduced in qa because the two jars were never the same. Interviewers ask this to see whether we understand the 'build once, deploy many' principle and how Spring Boot supports it. In this answer, we will look at the pattern, see its drawbacks, and then build the same service the recommended way, with configuration supplied at runtime.

1The Pattern We Are Replacing

In this pattern, each Maven profile points the build at a different resources folder, and the chosen folder's application.properties is packaged into the jar.

XML
<profiles>
<profile>
<id>dev</id>
<build><resources><resource><directory>src/main/config/dev</directory></resource></resources></build>
</profile>
<profile>
<id>prod</id>
<build><resources><resource><directory>src/main/config/prod</directory></resource></resources></build>
</profile>
</profiles>
# src/main/config/prod/application.properties
spring.datasource.url=jdbc:postgresql://prod-db:5432/orders
spring.datasource.password=S3cret! # a real password, now in Git and in the jar
$ mvn -Pqa package # orders-1.4.0.jar, built for qa
$ mvn -Pprod package # orders-1.4.0.jar again, but different contents

Notice the last two lines. Both builds produce a file with the same name and version, yet the contents differ. Nothing in the artifact repository tells us which environment a given orders-1.4.0.jar was built for.

2Why the Tested Artifact Is Not the Deployed Artifact

The whole point of testing in qa is to gain confidence in the thing we will deploy. When prod gets its own build, that confidence does not transfer. The prod build ran at a different time, perhaps resolved a newer SNAPSHOT dependency, perhaps used a different JDK on the build agent, and certainly packaged different files. A bug in prod's packaging, such as a typo in a property name, is never seen by qa at all.

It also slows delivery. Each environment needs its own build, and a hotfix has to be rebuilt per environment under pressure. And rollbacks are harder, because we must find the right environment's build of the previous version.

3Secrets Must Never Be Baked In

The second drawback is more serious. When prod configuration is packaged by a profile, the prod database password usually lives in the source repository and ends up inside the jar. Anyone who can read the repository or download the artifact can read the password, and rotating it means a new build and deployment. Secrets belong in a secret store, such as Vault, a cloud secrets manager or Kubernetes secrets, and reach the application at runtime, never through the build.

4Build Once, Configure at Runtime

Spring Boot is designed for the alternative. We build one jar containing only defaults that are safe everywhere. At startup, Spring Boot layers configuration from many sources on top of those defaults: profile-specific files activated by spring.profiles.active, environment variables, command-line arguments, mounted config files and, if we use one, a config service such as Spring Cloud Config. Later sources override earlier ones, so the environment decides the final values.

YAML
# inside the jar: src/main/resources/application.yaml
spring:
datasource:
url: jdbc:postgresql://localhost:5432/orders # safe default for local work
orders:
batch-size: 100
# deployed to prod, same jar, settings from the environment
$ SPRING_PROFILES_ACTIVE=prod \
SPRING_DATASOURCE_URL=jdbc:postgresql://prod-db:5432/orders \
SPRING_DATASOURCE_PASSWORD="$(read-secret orders/db)" \
java -jar orders-1.4.0.jar
# spring.datasource.url = jdbc:postgresql://prod-db:5432/orders (from the environment)
# orders.batch-size = 100 (from the jar)
Step throughOne artifact promoted through environments
CI buildArtifact repoqaprod
publish orders-1.4.0.jar once
deploy 1.4.0 with qa settings
tests pass on this exact jar
promote the same 1.4.0 with prod settings
rollback means redeploying 1.3.9

5 messages in order. Play them, or step through them one at a time.

Configuration and secrets come from each environment, not from the build.

Notice that environment variables map to properties by Spring Boot's relaxed binding: SPRING_DATASOURCE_URL becomes spring.datasource.url. The password comes from the secret store at deploy time and never touches the build. The same jar that passed qa is promoted, by version, to prod.

5What Maven Profiles Are Still Good For

Maven profiles remain useful for build concerns, things that change how we build, not what each environment receives. A profile that runs slow integration or performance tests only when asked, a native profile that compiles the service with GraalVM, and a release profile that signs artifacts and attaches sources and Javadoc are all good uses. None of them produces a per-environment artifact.

The table below sums up where each kind of setting belongs.

Where each setting belongs
SettingWhere it belongs
Database URL, service endpointsEnvironment variables or a config service
Passwords, API keysSecret store, injected at runtime
Feature differences per environmentSpring profiles such as prod and qa
Run slow tests, native image, release signingMaven profiles
Safe defaults for local workapplication.yaml inside the jar

6Migrating an Existing Service

We move one environment at a time. First we take the values from the profile folders and turn them into Spring profile files or environment variables, move every secret into the secret store and rotate it, because it has been in Git. Then we change the deployment of qa to use the single jar with runtime settings, and once it is stable, prod. Finally we delete the Maven environment profiles, so nobody can build a per-environment jar by accident.

7Follow-up questions

Is it acceptable to keep application-prod.yaml inside the jar?

It is acceptable for non-secret settings that really are part of the application's behaviour, such as log levels or feature flags, activated by spring.profiles.active=prod. The jar is still the same everywhere; only the active profile changes. Secrets and environment addresses are still better outside the jar, because they change without a new release.

How do you keep configuration for many environments manageable?

We keep it in one place per environment, such as a config repository served by Spring Cloud Config or a set of Kubernetes ConfigMaps managed by the deployment tooling, reviewed like code. The application then reads its settings at startup, and changes to configuration are tracked separately from changes to code.

What about Maven resource filtering for the version number?

Filtering build information such as the version or build time into a file is fine, because it is the same for every environment. Spring Boot's build-info goal does this for us. What we avoid is filtering environment-specific values, which brings back one jar per environment.

8Conclusion

In this answer, we saw that packaging configuration with dev, qa and prod Maven profiles produces different artifacts per environment, so the tested jar is not the deployed jar, and it tends to put secrets into Git and the jar. The better approach is to build once and promote the same artifact, with Spring Boot reading environment settings at runtime from Spring profiles, environment variables, a config service and a secret store. Maven profiles stay for build concerns such as slow tests, native builds and release signing.

What to say in the interviewAbout 80 seconds aloud

Open with

The main drawback is that we end up with a different jar per environment, so the artifact we tested in qa is not the artifact we deploy to prod.

Then, if they want more

They are built at different times, may resolve different dependencies, and package different files, so a mistake in prod's configuration is never tested. It also means hotfixes and rollbacks need per-environment builds, and in practice it usually puts prod passwords in Git and inside the jar, which is a real security problem.

What I would recommend is build once, deploy many. We build one jar with safe defaults and promote that exact version from qa to prod. Spring Boot reads environment settings at runtime: spring.profiles.active for environment-specific behaviour, environment variables such as SPRING_DATASOURCE_URL through relaxed binding, mounted files or a config service such as Spring Cloud Config.

Secrets come from a secret store like Vault or a cloud secrets manager, injected at deploy time, never through a Maven profile. Maven profiles are still useful, but for build concerns, like running slow integration tests on demand, building a native image or signing a release.

To migrate, I would move values into runtime configuration, move and rotate every secret, switch qa then prod to the single jar, and delete the environment profiles.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Maven guides
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A service uses Maven profiles dev, qa and prod to package different configuration files...": https://scrivio-interview-library.netlify.app/java/maven/ab6b24deab/