Skip to content

Instantly share code, notes, and snippets.

@falkorichter
Last active August 29, 2015 14:18
Show Gist options
  • Save falkorichter/fa5aa734b03c64bae592 to your computer and use it in GitHub Desktop.
Save falkorichter/fa5aa734b03c64bae592 to your computer and use it in GitHub Desktop.
Add all kinds of Jar tasks to your project
def generateJavadocJar = project.task("generateJavadocJars"){
description "Generate all Javadoc Jars of all Variants"
group 'jar'
}
def generateJavadoc = project.task("generateJavadocs"){
description "Generate all Javadoc of all Variants"
group 'jar'
}
def generateSourcesJar = project.task("generateSourcesJars"){
description "Generate all Sources Jars of all Variants"
group 'jar'
}
def generateProguardJar = project.task("generateProguardJars"){
description "Generate all Proguard Jars of all Variants"
group 'jar'
}
android.libraryVariants.all { variant ->
generateJavadoc.dependsOn project.task("${variant.name.capitalize()}Javadoc", type: Javadoc) {
destinationDir = new File("$project.buildDir/javadoc/$variant.name")
source = variant.javaCompile.source
ext.androidJar = "${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar"
classpath = project.files(variant.javaCompile.classpath.files) + project.files(ext.androidJar)
options {
linksOffline("http://d.android.com/reference", "${project.android.sdkDirectory}/docs/reference")
links("http://docs.oracle.com/javase/7/docs/api/");
setMemberLevel(JavadocMemberLevel.PACKAGE)
docEncoding = 'UTF-8'
encoding = 'UTF-8'
charSet = 'UTF-8'
}
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
generateJavadocJar.dependsOn project.task("generate${variant.name.capitalize()}JavadocJar", type: Jar, dependsOn: "${variant.name.capitalize()}Javadoc") {
classifier 'javadoc'
group 'jar'
description = "Assembles a jar archive containing the generated Javadoc API documentation of ${variant.name}."
destinationDir = new File("$project.buildDir/libs/")
exclude '**/BuildConfig.class'
exclude '**/R.class'
from "$project.buildDir/javadoc/$variant.name"
}
}
android.libraryVariants.all { variant ->
generateSourcesJar.dependsOn project.task("generate${variant.name.capitalize()}SourcesJar", type: Jar) {
classifier = 'sources'
group 'jar'
description = "Assembles a jar archive containing the main sources of ${variant.name}."
destinationDir = new File("$project.buildDir/libs/")
// exclude generated files
exclude '**/BuildConfig.java'
exclude '**/R.java'
from variant.javaCompile.source
}
}
android.libraryVariants.all { variant ->
generateProguardJar.dependsOn project.task("generate${variant.name.capitalize()}ProguardFilesJar", type: Zip) {
classifier 'proguard'
group 'jar'
description = "Assembles a jar archive containing the Proguard files of ${variant.name}."
destinationDir = new File("$project.buildDir/libs/")
from "$project.buildDir/outputs/mapping"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment