I am working an a library project for Android with Android Studio. The project contains a javadoc, but when I build a jar file with Gradle and use the library in another project, I cannot access the documentation.
Generating the html javadoc is possible, but not quite convenient. I want to have the documentation inside the jar file (which will be shipped to other users) to see it directly, eg using the Android Studio mouse-hover feature on the code.
Is there a way to include the javadoc into the generated jar file?
It is not possible to grab sources or javadoc from a compiled jar.
However build systems like gradle and maven support additional jars: If you upload your artifact to eg Maven central, just put an additional jar with a -sources
or -javadoc
suffix with the respective content in parallel to the main jar.
To generate these jars, use the following gradle tasks
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.