Prompt
Use environment variables and external configuration mechanisms instead of hard-coding values in build scripts. This makes your build system more flexible, maintainable, and adaptable to different environments.
Why it matters:
- Hard-coded values like file paths (e.g.,
/usr/bin/ccache) limit where tools can be installed - Project-specific constraints (e.g., spaces in project names causing Dokka errors) should be externalized
- Configuration options should be adaptable across different environments
How to implement:
- Replace hard-coded paths with environment variable lookups
- Use properties files or command-line parameters for configurable values
- Document configuration requirements clearly
Example: Instead of:
// Hard-coded paths that limit where ccache can be installed
val ccachePaths = listOf("/usr/bin/ccache", "/usr/local/bin/ccache")
Better approach:
// Use environment variables with fallbacks
val ccachePath = System.getenv("CCACHE_PATH")
?: listOf("/usr/bin/ccache", "/usr/local/bin/ccache").firstOrNull { file(it).exists() }
if (ccachePath != null) {
arguments("-DANDROID_CCACHE=$ccachePath")
}
Similarly, for dependency exclusions, use a consistent pattern:
configurations {
getByName("implementation") {
exclude(group = "commons-logging", module = "commons-logging")
exclude(group = "commons-collections", module = "commons-collections")
}
}