Skip to content

Add ability to publish JAR SDKs #1602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ gradlePlugin {
id = 'firebase-library'
implementationClass = 'com.google.firebase.gradle.plugins.FirebaseLibraryPlugin'
}

firebaseJavaLibraryPlugin {
id = "firebase-java-library"
implementationClass = 'com.google.firebase.gradle.plugins.FirebaseJavaLibraryPlugin'
}
}
}

Expand Down
162 changes: 88 additions & 74 deletions buildSrc/src/main/java/com/google/firebase/gradle/plugins/Dokka.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.android.build.gradle.LibraryExtension;
import com.google.common.collect.ImmutableMap;
import com.sun.istack.Nullable;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -29,6 +30,7 @@
import org.gradle.api.tasks.Copy;
import org.jetbrains.dokka.DokkaConfiguration;
import org.jetbrains.dokka.gradle.DokkaAndroidTask;
import org.jetbrains.dokka.gradle.DokkaTask;

final class Dokka {
/**
Expand All @@ -47,94 +49,63 @@ final class Dokka {
* <li>Remove the "https://firebase.google.com" prefix from all urls
*/
static void configure(
Project project, LibraryExtension android, FirebaseLibraryExtension firebaseLibrary) {
project.apply(ImmutableMap.of("plugin", "org.jetbrains.dokka-android"));
Project project,
@Nullable LibraryExtension android,
FirebaseLibraryExtension firebaseLibrary) {

String dokkaPluginName =
android == null ? "org.jetbrains.dokka" : "org.jetbrains.dokka-android";
project.apply(ImmutableMap.of("plugin", dokkaPluginName));

if (!firebaseLibrary.publishJavadoc) {
project.getTasks().register("kotlindoc");
return;
}
DokkaAndroidTask dokkaAndroidTask =
project
.getTasks()
.create(
"kotlindocDokka",
DokkaAndroidTask.class,
dokka -> {
dokka.setOutputDirectory(project.getBuildDir() + "/dokka/firebase");
dokka.setOutputFormat("dac");

dokka.setGenerateClassIndexPage(false);
dokka.setGeneratePackageIndexPage(false);
if (!project.getPluginManager().hasPlugin("kotlin-android")) {
dokka.dependsOn("docStubs");
dokka.setSourceDirs(
Collections.singletonList(
project.file(project.getBuildDir() + "/doc-stubs")));
}
Class<? extends DokkaTask> taskClass =
android == null ? DokkaTask.class : DokkaAndroidTask.class;
DokkaTask dokkaTask = configure(project, taskClass);

dokka.setNoAndroidSdkLink(true);
if (dokkaTask instanceof DokkaAndroidTask) {
((DokkaAndroidTask) dokkaTask).setNoAndroidSdkLink(true);

createLink(
project,
"https://developers.android.com/reference/kotlin/",
"kotlindoc/package-lists/android/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://developers.google.com/android/reference/",
"kotlindoc/package-lists/google/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://firebase.google.com/docs/reference/kotlin/",
"kotlindoc/package-lists/firebase/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/",
"kotlindoc/package-lists/coroutines/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
android
.getLibraryVariants()
.all(
v -> {
if (v.getName().equals("release")) {
project.afterEvaluate(
p -> {
FileCollection artifactFiles =
v.getRuntimeConfiguration()
.getIncoming()
.artifactView(
view -> {
view.attributes(
attrs ->
attrs.attribute(
Attribute.of("artifactType", String.class),
"jar"));
view.componentFilter(
c ->
!c.getDisplayName()
.startsWith("androidx.annotation:annotation:"));
})
.getArtifacts()
.getArtifactFiles()
.plus(project.files(android.getBootClasspath()));
dokkaTask.setClasspath(artifactFiles);
});
}
});
}

android
.getLibraryVariants()
.all(
v -> {
if (v.getName().equals("release")) {
project.afterEvaluate(
p -> {
FileCollection artifactFiles =
v.getRuntimeConfiguration()
.getIncoming()
.artifactView(
view -> {
view.attributes(
attrs ->
attrs.attribute(
Attribute.of(
"artifactType", String.class),
"jar"));
view.componentFilter(
c ->
!c.getDisplayName()
.startsWith(
"androidx.annotation:annotation:"));
})
.getArtifacts()
.getArtifactFiles()
.plus(project.files(android.getBootClasspath()));
dokka.setClasspath(artifactFiles);
});
}
});
});
project
.getTasks()
.create(
"kotlindoc",
Copy.class,
copy -> {
copy.dependsOn(dokkaAndroidTask);
copy.dependsOn(dokkaTask);
copy.setDestinationDir(
project.file(project.getRootProject().getBuildDir() + "/firebase-kotlindoc"));
copy.from(
Expand All @@ -161,6 +132,49 @@ static void configure(
});
}

static <T extends DokkaTask> T configure(Project project, Class<T> taskType) {
return project
.getTasks()
.create(
"kotlindocDokka",
taskType,
dokka -> {
dokka.setOutputDirectory(project.getBuildDir() + "/dokka/firebase");
dokka.setOutputFormat("dac");

dokka.setGenerateClassIndexPage(false);
dokka.setGeneratePackageIndexPage(false);
if (!project.getPluginManager().hasPlugin("kotlin-android")) {
dokka.dependsOn("docStubs");
dokka.setSourceDirs(
Collections.singletonList(project.file(project.getBuildDir() + "/doc-stubs")));
}

dokka.setNoJdkLink(true);

createLink(
project,
"https://developers.android.com/reference/kotlin/",
"kotlindoc/package-lists/android/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://developers.google.com/android/reference/",
"kotlindoc/package-lists/google/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://firebase.google.com/docs/reference/kotlin/",
"kotlindoc/package-lists/firebase/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
createLink(
project,
"https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/",
"kotlindoc/package-lists/coroutines/package-list")
.map(dokka.getExternalDocumentationLinks()::add);
});
}

private static Optional<DokkaConfiguration.ExternalDocumentationLink> createLink(
Project project, String url, String packageListPath) {

Expand Down
Loading