Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android library artifact tasks
if (project.android.hasProperty('libraryVariants')) {
android.libraryVariants.all { variant ->
Task javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
group = 'artifact'
description "Generates Javadoc for $variant.name"
// Source files from the variant
source = variant.javaCompiler.source
// Classpath from the variant + android.jar
String androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = variant.javaCompiler.classpath + files(androidJar)
// The Android online reference doesn't include package-list, so we have to use the local one
String packageListRef = "${android.sdkDirectory}/docs/reference/"
options.linksOffline 'http://d.android.com/reference/', packageListRef
// Additional links for any RxJava references
options.links 'http://reactivex.io/RxJava/javadoc/'
// Exclude generated files
exclude '**/BuildConfig.java'
exclude '**/R.java'
// Output to a unique javadoc folder per variant
destinationDir = new File(project.docsDir, "javadoc-$variant.name")
}
task("generate${variant.name.capitalize()}JavadocJar", type: Jar, dependsOn: javadocTask) {
group = 'artifact'
description = "Generates Javadoc jar for $variant.name"
classifier = "$variant.name-javadoc"
from javadocTask.destinationDir
}
task("generate${variant.name.capitalize()}SourcesJar", type: Jar) {
group = 'artifact'
description = "Generates sources jar for $variant.name"
classifier = "$variant.name-sources"
from variant.javaCompiler.source
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.