Created
September 22, 2016 06:20
-
-
Save guiguegon/9ae8632e2ee3c9a1b235d035d3a824ab to your computer and use it in GitHub Desktop.
Gradle rename plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomPlugin implements Plugin<Project> { | |
@Override | |
void apply(Project project) { | |
project.task('renameAppVersionName', type: RenameAppVersionNameTask) | |
project.tasks.getByName('preBuild').dependsOn('renameAppVersionName') | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RenameAppVersionNameTask extends DefaultTask { | |
@TaskAction | |
def run() { | |
project.configure(project) { | |
// Check if plugin works on an Android module | |
if (it.hasProperty("android")) { | |
// Iterate over app build variants (build types + flavors) | |
project.android.applicationVariants.all { variant -> | |
// Only change debug build type variants | |
if (variant.buildType.name == project.android.buildTypes.debug.name) { | |
// Rename versionName | |
def customVersionName = variant.mergedFlavor.versionName | |
variant.mergedFlavor.versionName = customVersionName + " custom" | |
} | |
} | |
} | |
} | |
} | |
RenameAppVersionNameTask() { | |
group = 'customPlugin' | |
description = 'Renames versionName of the app depends on the current git branch name' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use | |
apply plugin: CustomPlugin | |
// src | |
buildSrc/src/main/groovy/es/guiguegon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment