This is a template project on Gradle plugins for Android. The plugin/ directory is the main
module that implements a Gradle plugin, including a plugin class, an extension class, and a task
class.
plugin/ - The main module of a Gradle plugin
example/ - An example android application that uses this plugin
buildSrc/ - A helper module to use this plugin in example modules
Copy gradle.properties.sample into ~/.gradle/gradle.properties and set correct values.
Note that PGP_KEY_ID is the value that gpg --list-secret-keys shows.
Reading resources from plugin.jar is extremely unstable so you'll see a method in
FooTask.groovy:
String getResourceContent(String filename) {
URL templateFileUrl = getClass().getClassLoader().getResource(filename)
if (templateFileUrl == null) {
throw new GradleException("[${this.tag}] File not found: $filename")
}
try {
return templateFileUrl.openStream().getText("UTF-8")
} catch (IOException e) {
// fallback to read JAR directly
def connection = templateFileUrl.openConnection() as JarURLConnection
def jarFile = connection.jarFileURL.toURI()
ZipFile zip
try {
zip = new ZipFile(new File(jarFile))
} catch (FileNotFoundException ex) {
project.logger.warn("[${this.tag}] No plugin.jar. run `./gradlew plugin:jar` first.")
throw ex
}
return zip.getInputStream((zip.getEntry(filename))).getText("UTF-8")
}
}It looks strange but works anyway. I don't know whether it is intended or not.
Copyright 2014, FUJI Goro (gfx) gfuji@cpan.org. All rights reserved.
This library may be copied only under the terms of the Apache License 2.0, which may be found in the distribution.