Java › Build Tools: Maven & Gradle
How do you manage different configurations for different environments (development, staging, production) using Maven profiles or Gradle's equivalent mechanisms?
IntermediateAnswer
Maven profiles (<profiles> in pom.xml, activated via -P flag, an environment variable, or automatic activation conditions) let you conditionally include different dependencies, properties, or plugin configurations depending on which profile is active -- Gradle typically achieves the same outcome more flexibly through plain conditional logic in the build script itself (checking a project property or environment variable), or through separate source sets/build variants, since Gradle's scripting nature doesn't require a dedicated "profile" abstraction the way Maven's declarative model does.
<!-- Maven profile for production-specific configuration -->
<profiles>
<profile>
<id>production</id>
<properties>
<log.level>WARN</log.level>
</properties>
</profile>
</profiles>
# Activate explicitly
mvn package -PproductionReal-world example A CI/CD pipeline activates a different Maven profile depending on the deployment target (dev, staging, production), each profile substituting the appropriate database connection properties and logging configuration into the packaged artifact without maintaining entirely separate pom.xml files per environment.