Skip to content

Instantly share code, notes, and snippets.

@tmelz
Created February 26, 2016 02:53
Show Gist options
  • Save tmelz/6f93e6a68343210043c2 to your computer and use it in GitHub Desktop.
Save tmelz/6f93e6a68343210043c2 to your computer and use it in GitHub Desktop.
enforce your android versionName format with a regexp
android {
defaultConfig {
// Version name format: A.B.C-D, with A, B, and C numbers with -D optional as either "ALPHA"
// or "BETA" followed by a description. Examples: "1.0.0", "1.0.0-BETA",
// "1.0.0-ALPHA-TACO-DELIVERY".
versionName "1.0.0"
// Enforce that the version name matches the required format.
if (!(versionName ==~ /\d+\.\d+\.\d+(-(ALPHA|BETA).*)?/)) {
throw new IllegalStateException(
"Invalid version name ('$versionName')! See comment in app/build.gradle")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment