Created
January 7, 2017 08:27
-
-
Save 2BAB/c499ba64c6a2566fd7d6be0432ca62a6 to your computer and use it in GitHub Desktop.
registerJavaGeneratingTask
This file contains 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
public class GenExcaliburMapTask extends DefaultTask { | |
@OutputDirectory | |
File outputDir | |
@Input | |
String outputPackageName | |
@TaskAction | |
def generateMap() { | |
outputDir.deleteDir() | |
TypeSpec typeSpec = TypeSpec.classBuilder("ExcaliburMap").addModifiers(Modifier.PUBLIC).build() | |
JavaFile mapFile = JavaFile.builder(outputPackageName, typeSpec) | |
.addFileComment("Generated by 2BAB.") | |
.build() | |
mapFile.writeTo(outputDir) | |
} | |
} |
This file contains 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
project.afterEvaluate { | |
project.android.applicationVariants.all { variant -> | |
def genTask = project.tasks.create(name: "genearte${variant.name.capitalize()}ExcaliburMap", type: GenExcaliburMapTask) | |
// get output dir | |
File genDir = new File(project.buildDir, "generated/source/saber/${variant.dirName}") | |
genTask.outputDir = genDir | |
// get output package name | |
// def buildConfig = variant.generateBuildConfig | |
// buildConfig.doLast { | |
// def packageName = buildConfig.appPackageName | |
// log.debug "SaberGradlePlugin: [${variant.name}] packageName: $packageName" | |
// genTask.outputPackageName = packageName | |
// } | |
def applicationId = [variant.mergedFlavor.applicationId, variant.buildType.applicationIdSuffix].findAll().join() | |
genTask.outputPackageName = applicationId | |
// add task to generatingTask | |
variant.registerJavaGeneratingTask genTask, genDir | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment