I need to upload my libraries(multi-module project) into sonatype repository through Bintray. So that I need to generate the Javadoc individually for each module.
First I faced the problems in these similar questions
Android Studio Javadoc: Cannot find symbol
Gradle Javadoc fails with “error: package … does not exist”</a>
From the solution in the first question, I can resolve the classes that I have used from third party libraries(retrofit2, gson) and @NonNull
annotations errors.
But in my case one of my modules(Lib2
) depends on another module(Lib1
).
When generating the Javadoc for Lib2
module, its warning package does not exist
& cannot find symbol
for the classes of another module(Lib1
).
And both modules reports package does not exist
error for android support & design libraries.
And Every import <packagename>.R;
reports cannot find symbol
My Javadoc generating task
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
project.android.libraryVariants.all { variant ->
classpath += files(variant.javaCompile.classpath.files)
}
}
dependencies in Lib1 build.gradle
compile rootProject.appcompat
compile rootProject.design
compile rootProject.retrofit2
compile rootProject.support
compile rootProject.gsonConverter
compile rootProject.httpLogInterceptor
compile rootProject.universalImageLoader
dependencies in Lib2 build.gradle
compile project(':core')
compile rootProject.appcompat
compile rootProject.design
compile rootProject.retrofit2
compile rootProject.support
compile rootProject.cardview
I have tried
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
}
My entire gradle-mvn-push.gradle
apply plugin: 'maven'
apply plugin: 'com.jfrog.bintray'
// Declaring variables
afterEvaluate { project ->
bintray {
user = bin_user
key = bin_key
configurations = ['archives']
publish = true
dryRun = false
pkg {
repo = REPO
name = POM_ARTIFACT_ID
userOrg = USER_ORG
desc = POM_DESCRIPTION
websiteUrl = POM_URL
vcsUrl = GIT_URL
licenses = ['Apache-2.0']
version {
name = VERSION_NAME
vcsTag = VERSION_NAME
gpg {
sign = true
try {
passphrase = PASS_PHRASE
} catch (Exception ignored) {
println 'Failed to find credentials. GPG sign disabled'
}
}
}
}
}
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
task install(type: Upload, dependsOn: assemble) {
repositories.mavenInstaller {
configuration = configurations.archives
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id pom_developer_id
name pom_developer_name
}
}
}
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
project.android.libraryVariants.all { variant ->
classpath += files(variant.javaCompile.classpath.files)
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}
} else {
install {
repositories.mavenInstaller {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn:javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
}
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
artifacts {
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
archives androidSourcesJar
archives androidJavadocsJar
} else {
archives sourcesJar
archives javadocJar
}
}
}