Build Tools · Lesson 10
Build Profiles and Environments
Adapting a Build to an Environment
A build profile selects configuration for a context such as development, testing, or production. Profiles can change endpoints, logging, feature flags, and packaging details, but secrets should come from secure runtime configuration. The goal is one repeatable build process with explicit differences.
Reading an Environment Property
Java code can read a property supplied by the build or deployment environment. Keep defaults safe for local work and validate required production values at startup.
public class EnvironmentSettings {
public static void main(String[] arguments) {
String environmentName = System.getProperty("app.environment", "development");
boolean verboseLogging = Boolean.parseBoolean(
System.getProperty("app.verboseLogging", "true"));
System.out.println(environmentName + "; verbose logging: " + verboseLogging);
}
}
Profile Comparison
| Environment | Typical settings | Main goal |
|---|---|---|
| Development | Local database, verbose logs | Fast feedback |
| Test | Isolated services, test data | Repeatable verification |
| Staging | Production-like infrastructure | Release confidence |
| Production | Secure endpoints, limited logs | Reliability and safety |
Common Mistake and Practices
Common Mistake: Committing credentials into a profile file because it is convenient. Repository history and build logs can expose secrets long after the file is deleted.
- Keep secrets outside source control.
- Name profiles explicitly in CI.
- Validate required properties early.
- Keep profile differences minimal.
- Test the production profile before release.
Real-World Use Case
The academy uses a test profile with an isolated database and a production deployment that supplies credentials through a secret manager. The application code stays unchanged between environments.
Quiz Check