1、文档注释写法:
afterEvaluate { project ->
// 写法一(网上通用):
// task androidJavadocs(type: Javadoc) {
// source = android.sourceSets.main.java.srcDirs
// classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// }
// task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
// classifier = 'javadoc'
// from androidJavadocs.destinationDir
// }
// task androidSourcesJar(type: Jar) {
// classifier = 'sources'
// from android.sourceSets.main.java.sourceFiles
// }
//
解决 JavaDoc 中文注释生成失败的问题
// tasks.withType(Javadoc) {
// options.addStringOption('Xdoclint:none', '-quiet')
// options.addStringOption('encoding', 'UTF-8')
// options.addStringOption('charSet', 'UTF-8')
// }
//
// artifacts {
// archives androidSourcesJar
// archives androidJavadocsJar
// }
// 写法二(LegoArch):
if (project.hasProperty("android")) {
task androidJavadoc(type: Javadoc) {
options {
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/8/docs/api/"
linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
}
destinationDir = file("./javadoc/")
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
exclude('**/BuildConfig.java',
'**/R.java',
'**/*.aidl')
failOnError = false
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourceJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
// from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourceJar
archives androidJavadocJar
}
}
}