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.
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:
/usr/bin/ccache
) limit where tools can be installedHow to implement:
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")
}
}
Enter the URL of a public GitHub repository