Skip to content

Instantly share code, notes, and snippets.

@vrunoa
Last active January 14, 2016 20:12
Show Gist options
  • Save vrunoa/1db6dfef2f4b87ae9e12 to your computer and use it in GitHub Desktop.
Save vrunoa/1db6dfef2f4b87ae9e12 to your computer and use it in GitHub Desktop.
Create a task on gradle to get android project versionName from cli
apply plugin: 'com.android.library'
apply plugin: Version
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'io.socket:socket.io-client:0.6.2'
}
// add the gradle task
class Version implements Plugin<Project>{
public void apply(Project project) {
project.task("Version") {
project.gradle.projectsEvaluated {
println "$project.android.defaultConfig.versionName"
}
}
}
}
// run ./gradlew -q Version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment