diff --git a/build.gradle b/build.gradle index 0209da0a1..b27746e92 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'com.vanniktech.maven.publish' apply from: "$rootDir/gradle/jacoco-root.gradle" ext { - splitVersion = '5.5.0-rc6' + splitVersion = '5.5.0-rc7' jacocoVersion = '0.8.8' } @@ -145,6 +145,68 @@ dependencies { include project(':api') } +def javadocSourceProjects = providers.provider { + def includeConfig = configurations.findByName("include") + if (includeConfig == null) { + return [] + } + includeConfig.allDependencies + .withType(org.gradle.api.artifacts.ProjectDependency) + .collect { dep -> + def projectPath = null + if (dep.metaClass.hasProperty(dep, 'dependencyProject')) { + projectPath = dep.dependencyProject?.path + } else if (dep.metaClass.hasProperty(dep, 'dependencyProjectPath')) { + projectPath = dep.dependencyProjectPath + } else if (dep.metaClass.hasProperty(dep, 'path')) { + projectPath = dep.path + } + return projectPath ? project(projectPath) : null + } + .findAll { it != null } +} + +def javadocSourceDirsProvider = providers.provider { + files(javadocSourceProjects.get().collect { sourceProject -> + def androidExtension = sourceProject.extensions.findByName("android") + def sourceDirs = androidExtension?.sourceSets?.main?.java?.srcDirs ?: [] + return sourceDirs.findAll { it.exists() } + }) +} + +def sourcesJarTask = tasks.register('sourcesJar', Jar) { + archiveBaseName = 'android-client' + archiveVersion = splitVersion + archiveClassifier = 'sources' + destinationDirectory = layout.buildDirectory.dir('libs') + from(javadocSourceDirsProvider) +} + +tasks.register('javadocJar', Jar) { + archiveBaseName = 'android-client' + archiveVersion = splitVersion + archiveClassifier = 'javadoc' + destinationDirectory = layout.buildDirectory.dir('libs') + def javadocDir = layout.buildDirectory.dir('intermediates/java_doc_dir/release') + from(javadocDir) + doFirst { + if (!javadocDir.get().asFile.exists()) { + throw new GradleException("Javadoc directory not found: ${javadocDir.get().asFile}") + } + } +} + +afterEvaluate { + def agpJavadocTask = tasks.findByName('javaDocRelease') ?: + tasks.findByName('javaDocJar') ?: + tasks.findByName('javaDoc') + if (agpJavadocTask != null) { + tasks.named('javadocJar').configure { + dependsOn agpJavadocTask + } + } +} + def splitPOM = { name = 'Split Android SDK' description = 'Official Split Android SDK' @@ -377,6 +439,8 @@ afterEvaluate { // This causes lint to crash when consumers use checkDependencies: true publishing.publications.withType(MavenPublication) { publication -> if (publication.name == "maven") { + publication.artifact(tasks.named('javadocJar')) + publication.artifact(tasks.named('sourcesJar')) publication.artifacts.removeAll { artifact -> artifact.file?.name?.endsWith('lint.jar') ?: false } @@ -393,16 +457,18 @@ gradle.taskGraph.whenReady { graph -> publishTask.doFirst { def pub = publication if (pub.name == "maven") { + def sourcesJarFile = tasks.named('sourcesJar').get().archiveFile.get().asFile def sourcesArtifacts = pub.artifacts.findAll { it.classifier == "sources" && it.extension == "jar" } - if (sourcesArtifacts.size() > 1) { - // Keep the AGP one (merged_sources_jar), remove the vanniktech empty one (build/libs) - def toRemove = sourcesArtifacts.find { - it.file?.absolutePath?.contains("build/libs") || it.file?.name?.contains("android-client-sources") - } - if (toRemove) { - pub.artifacts.remove(toRemove) - println "Removed duplicate empty sources artifact: ${toRemove.file?.absolutePath}" - } + sourcesArtifacts.findAll { it.file != null && it.file != sourcesJarFile }.each { artifact -> + pub.artifacts.remove(artifact) + println "Removed duplicate sources artifact: ${artifact.file?.absolutePath}" + } + + def javadocJarFile = tasks.named('javadocJar').get().archiveFile.get().asFile + def javadocArtifacts = pub.artifacts.findAll { it.classifier == "javadoc" && it.extension == "jar" } + javadocArtifacts.findAll { it.file != null && it.file != javadocJarFile }.each { artifact -> + pub.artifacts.remove(artifact) + println "Removed duplicate javadoc artifact: ${artifact.file?.absolutePath}" } } }