Gradle task to generate Javadoc
The task definition shouldn't be within the Android block and in this case, its used in an application project. For a library project, just replace android.applicationVariants to android.libraryVariants. The task refers to the source code and the Android's SDK jar and excludes build generated source files.
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.applicationVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
title = "$name $version API"
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Once defined and synced, the task should appear in the Gradle tasks section. Clicking on either the debug or release version should save the javadocs in build/docs/javadoc under the application directory and the actual javadoc options is saved in build/tmp/generatedebugJavadoc under a file named javadoc.options.
The task definition shouldn't be within the Android block and in this case, its used in an application project. For a library project, just replace android.applicationVariants to android.libraryVariants. The task refers to the source code and the Android's SDK jar and excludes build generated source files.
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.applicationVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
title = "$name $version API"
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Once defined and synced, the task should appear in the Gradle tasks section. Clicking on either the debug or release version should save the javadocs in build/docs/javadoc under the application directory and the actual javadoc options is saved in build/tmp/generatedebugJavadoc under a file named javadoc.options.
2 comments:
Doesn't work anymore
Doesn't work as in? I used in this Studio 1.0
Post a Comment