Quick revision
The short answer
A profile marked activeByDefault is only active when no other profile in the same POM is activated. The moment a developer runs mvn -Pfast verify, the fast profile is activated explicitly, so Maven switches the default one off. For defaults that should stay on, activate the profile by a property instead, for example 'active unless -DskipChecks is set', check what is active with mvn help:active-profiles, and keep profiles away from anything that changes the artifact being produced.
What to remember
In this answer, we saw that activeByDefault is a fallback that applies only when no other profile in the same POM is active, which is why -Pfast switches it off. For defaults that must stay on, property-based activation with a negated property such as !skipChecks keeps the profile independent of other profiles. We also met the other triggers, JDK, operating system and file presence, used mvn help:active-profiles to see what is active, and saw why profiles should never change the artifact we ship.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A profile marked activeByDefault is only active when no other profile in the same POM is activated. The moment a developer runs mvn -Pfast verify, the fast profile is activated explicitly, so Maven switches the default one off. For defaults that should stay on, activate the profile by a property instead, for example 'active unless -DskipChecks is set', check what is active with mvn help:active-profiles, and keep profiles away from anything that changes the artifact being produced.
Why this question is asked
Profiles are Maven's way of switching parts of the build on and off, and activeByDefault sounds like exactly the right tool for 'on unless I say otherwise'. It is not, and the surprise usually shows up as a quality check or a code generation step that silently stops running on someone's machine. Interviewers ask this because it tests whether we have debugged a real build, not just read the POM. In this answer, we will recap what profiles are, reproduce the problem, see why Maven behaves this way, and then look at better ways to activate profiles and how to check which ones are active.
1A Quick Recap of Maven Profiles
A profile is a named block of POM configuration that is only applied when the profile is active. It can add plugins, change properties, add dependencies or modules. We can activate a profile explicitly on the command line with -P followed by its id, or automatically through an activation section that describes when it should apply.
The activation section supports several triggers: a property (present, absent or with a given value), the JDK version, the operating system, the presence or absence of a file, and activeByDefault. Each answers a different question, and activeByDefault answers a narrower question than its name suggests.
2Reproducing the Problem
Suppose our POM has two profiles: checks, which runs the static analysis plugins and is meant to be on by default, and fast, which skips slow integration tests.
Notice that asking for fast did not add it next to checks; it replaced it. The developer wanted a faster build, and without noticing they also switched off the static analysis, so problems slip through until CI catches them, or worse, until nobody does because CI also passes a profile.
3Why activeByDefault Behaves This Way
The rule in Maven is that a profile with activeByDefault is active only if no other profile in the same POM is active, whether by -P or by its own activation trigger. It is designed as a fallback, 'use this when nothing else is chosen', not as 'always on'. So activating fast explicitly counts as choosing something, and the fallback is dropped.
There is a second, quieter way to hit this. If another profile in the same POM becomes active automatically, for example one activated when the JDK is 25, the default profile also switches off, even though nobody typed -P. That makes the build behave differently on different machines, which is the worst kind of build bug.
- Is any other profile in this POM active?YesDefault profile is switched offNoDefault profile is applied
- Other profile active how?-P on the command line, or its own trigger such as JDK or a property
2 steps in order. Play them, or step through them one at a time.
4A Better Default: Activate by a Missing Property
For 'on unless I say otherwise', we activate the profile when a property is absent. In Maven, a property name starting with an exclamation mark means 'activate when this property is not set'. Now the profile stays on whatever other profiles are chosen, and a developer switches it off deliberately with -D.
So the two concerns are now independent. Turning on fast no longer turns off checks, and turning off checks is explicit and visible in the command. We can also deactivate any profile explicitly with -P!checks (or -P-checks), which is useful for a one-off run.
5Other Activation Triggers and Checking What Is Active
Besides properties, a profile can be activated by the JDK, for example jdk set to [25,) for Java 25 and later; by the operating system, for example family set to windows to add a Windows-specific path; and by a file, for example activate the code generation profile only when src/main/proto exists. These are useful when the build really has to adapt to its environment or contents.
Whenever a profile seems to misbehave, the first command to run is mvn help:active-profiles, which lists the active profiles and where each one came from: this POM, a parent or settings.xml. mvn help:effective-pom then shows the final configuration after profiles are applied, so we can confirm whether the plugin we expect is really there.
6Keep Profiles Away From the Artifact
There is a deeper lesson in this bug. A profile that is on in one place and off in another makes the build depend on who runs it and how. That is acceptable for things that do not change the output, such as running extra checks or skipping slow tests. It is a problem when a profile changes what goes into the jar, such as different resources, dependencies or generated code, because then two builds of the same commit produce different artifacts. Profiles should change how we build, not what we ship.
7Follow-up questions
Does activeByDefault interact with profiles from settings.xml or the parent?
The rule applies to profiles in the same POM. A profile activated in settings.xml or in a parent POM does not switch off the default profile of this POM. That is another reason the behaviour feels inconsistent, and another reason to prefer property-based activation, whose behaviour does not depend on what other profiles exist.
How do you switch a profile off from the command line?
Prefix its id with an exclamation mark or a minus sign in -P, for example mvn -P!checks verify or mvn -P-checks verify. In shells like bash, the exclamation mark may need quoting, so the minus form is often easier.
Is it a good idea to activate profiles in settings.xml for everyone?
Only for machine-level concerns such as repository credentials or a proxy. If a build's correctness depends on a profile defined in a developer's settings.xml, it will behave differently on another machine and in CI, so project build behaviour belongs in the POM.
8Conclusion
In this answer, we saw that activeByDefault is a fallback that applies only when no other profile in the same POM is active, which is why -Pfast switches it off. For defaults that must stay on, property-based activation with a negated property such as !skipChecks keeps the profile independent of other profiles. We also met the other triggers, JDK, operating system and file presence, used mvn help:active-profiles to see what is active, and saw why profiles should never change the artifact we ship.
Open with
The reason is how Maven defines activeByDefault. It is a fallback: the profile is active only when no other profile in the same POM is active. When the developer runs mvn -Pfast verify, the fast profile is activated explicitly, so Maven drops the default profile, and whatever it did, say running Checkstyle and SpotBugs, silently stops.
Then, if they want more
The same thing happens if another profile in that POM activates automatically, for example by JDK version, so the build can behave differently on different machines. I would confirm it with mvn help:active-profiles, which lists what is active and where it came from, and use help:effective-pom to see the final plugin configuration.
The fix for 'on unless I say otherwise' is property-based activation with a negated property, so the profile is active when, say, skipChecks is not set. Then -Pfast adds the fast profile alongside checks, and someone who really wants to skip the checks passes -DskipChecks, which is explicit.
Other useful triggers are JDK version, operating system and file presence, such as enabling code generation only if a proto folder exists. And I would keep profiles for build concerns only. A profile that changes what ends up in the jar makes the artifact depend on who built it, which I would avoid.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25
- 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 Maven profile marked activeByDefault stops applying as soon as a developer runs 'mvn...": https://scrivio-interview-library.netlify.app/java/maven/da78a55e93/