Skip to content

Add MultiProjectReleasePlugin #2455

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 1 commit into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
68 changes: 68 additions & 0 deletions alternative-root-project.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import com.google.firebase.gradle.MultiProjectReleasePlugin

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlinVersion = '1.3.72'
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url 'https://storage.googleapis.com/android-ci/mvn/'
}
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.3'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.2.1'
classpath 'org.jsoup:jsoup:1.11.2'
classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8'
classpath 'com.google.gms:google-services:4.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.7.1'
classpath 'digital.wup:android-maven-publish:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'org.jlleitschuh.gradle:ktlint-gradle:7.1.0'
}
}

ext {
playServicesVersion = '16.0.1'
supportAnnotationsVersion = '28.0.0'
gMavenRoot = 'https://dl.google.com/dl/android/maven2'
firebaseDefaultPreguardFile='oss/default-preguard.txt'
errorproneVersion = '2.3.2'
errorproneJavacVersion = '9+181-r4173-1'
googleTruthVersion = '0.40'

}

apply from: 'build.gradle'

configure(subprojects) {
afterEvaluate {
tasks.verifyGoogleJavaFormat {
exclude '**/build/classes/**'
}
}
}

apply plugin: MultiProjectReleasePlugin
26 changes: 26 additions & 0 deletions alternative-settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

rootProject.name = 'com.google.firebase'
//Note: do not add subprojects to this file. Instead add them to subprojects.gradle

apply from: 'gradle/projectSettings.gradle'

discoverSubprojects(file('subprojects.cfg')).each {
include ":$it"
}

apply from: new File(settingsDir, 'gradle/buildCache.gradle')

rootProject.buildFileName = 'alternative-root-project.gradle'
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.firebase.gradle;

import static com.google.firebase.gradle.plugins.ProjectUtilsKt.toBoolean;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.gradle.bomgenerator.BomGeneratorTask;
import com.google.firebase.gradle.plugins.FireEscapeArtifactPlugin;
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension;
import com.google.firebase.gradle.plugins.JavadocPlugin;
import com.google.firebase.gradle.plugins.TasksKt;
import com.google.firebase.gradle.plugins.publish.PublishingPlugin;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Set;
import java.util.stream.Collectors;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.Delete;
import org.gradle.api.tasks.bundling.Zip;

/**
* Orchestrates the release process by automating validations, documentation and prebuilts
* generation.
*
* <ul>
* <li>Pre-release validations:
* <ul>
* <li>Build maven artifacts.
* </ul>
* <li>Documentation:
* <ul>
* <li>Generates javadoc for all SDKs being released.
* </ul>
* <li>Artifact generation:
* <ul>
* <li>Releases artifacts into a maven repo in build/m2repository.
* <li>Bundles all artifacts into a distributable .zip file.
* </ul>
* </ul>
*/
public class MultiProjectReleasePlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
project.apply(ImmutableMap.of("plugin", PublishingPlugin.class));

boolean releaseJavadocs = toBoolean(System.getProperty("releaseJavadocs", "true"));

File firebaseDevsiteJavadoc = new File(project.getBuildDir(), "firebase-javadocs/");
firebaseDevsiteJavadoc.mkdirs();
File gmsDevsiteJavadoc = new File(project.getBuildDir(), "gms-javadocs/");
gmsDevsiteJavadoc.mkdirs();
File firebaseClientBuildDest = new File(firebaseDevsiteJavadoc, "client/");
firebaseClientBuildDest.mkdirs();
File gmsClientBuildDest = new File(gmsDevsiteJavadoc, "client/");
gmsClientBuildDest.mkdirs();

project.subprojects(
sub -> {
sub.afterEvaluate(
p -> {
sub.apply(ImmutableMap.of("plugin", JavadocPlugin.class));
sub.apply(ImmutableMap.of("plugin", FireEscapeArtifactPlugin.class));
});
});

project
.getTasks()
.create(
"buildBomZip",
Zip.class,
task -> {
task.dependsOn(project.getTasks().create("generateBom", BomGeneratorTask.class));
task.from("bom");
task.getArchiveFileName().set("bom.zip");
task.getDestinationDirectory().set(project.getRootDir());
});

project
.getGradle()
.projectsEvaluated(
gradle -> {
Set<FirebaseLibraryExtension> librariesToPublish =
(Set<FirebaseLibraryExtension>)
project.getExtensions().getExtraProperties().get("projectsToPublish");

Set<Project> projectsToPublish =
librariesToPublish.stream().map(lib -> lib.project).collect(Collectors.toSet());

Task validateProjectsToPublish =
project.task(
"validateProjectsToPublish",
task ->
task.doLast(
t -> {
if (projectsToPublish.isEmpty()) {
throw new GradleException(
"Required projectsToPublish parameter missing.");
}
}));
Task firebasePublish = project.getTasks().findByName("firebasePublish");
firebasePublish.dependsOn(validateProjectsToPublish);

Task generateAllJavadocs =
project.task(
"generateAllJavadocs",
task -> {
for (Project p : projectsToPublish) {
task.dependsOn(p.getPath() + ":" + TasksKt.JAVADOC_TASK_NAME);

task.doLast(
t -> {
for (Project publishableProject : projectsToPublish) {
publishableProject.copy(
copy -> {
copy.from(
publishableProject.getBuildDir()
+ "/docs/javadoc/reference");
copy.include("**/*");
copy.into(firebaseDevsiteJavadoc);
});

publishableProject.copy(
copy -> {
copy.from(
publishableProject.getBuildDir()
+ "/docs/javadoc/reference");
copy.include("**/*");
copy.into(gmsDevsiteJavadoc);
});

publishableProject.copy(
copy -> {
copy.from(
publishableProject.getBuildDir()
+ "/docs/javadoc/reference/_toc.yaml");
copy.include("**/*");
copy.into(
firebaseClientBuildDest
+ "/"
+ publishableProject.getName());
});

publishableProject.copy(
copy -> {
copy.from(
publishableProject.getBuildDir()
+ "/docs/javadoc/reference/_toc.yaml");
copy.include("**/*");
copy.into(
gmsClientBuildDest
+ "/"
+ publishableProject.getName());
});
}
});
}
});

Delete prepareJavadocs =
project
.getTasks()
.create(
"prepareJavadocs",
Delete.class,
del -> {
del.dependsOn(generateAllJavadocs);
del.doLast(
d -> {
// cleanup docs
project.delete(
delSpec -> {
ImmutableList<String> relativeDeletablePaths =
ImmutableList.of(
"timestamp.js",
"navtree_data.js",
"assets/",
"classes.html",
"hierarchy.html",
"lists.js",
"package-list",
"packages.html",
"index.html",
"current.xml",
"_toc.yaml");
delSpec.delete(
relativeDeletablePaths.stream()
.flatMap(
path ->
ImmutableList.of(
firebaseDevsiteJavadoc.getPath()
+ "/"
+ path,
gmsDevsiteJavadoc.getPath()
+ "/"
+ path)
.stream())
.collect(Collectors.toList()));
});
// Transform
project.exec(
execSpec -> {
execSpec.setIgnoreExitValue(true);
execSpec.setWorkingDir(firebaseDevsiteJavadoc);
execSpec.setCommandLine(
project.getRootProject().file("buildSrc").getPath()
+ "/devsite_transform.sh");
});

project.exec(
execSpec -> {
execSpec.setIgnoreExitValue(true);
execSpec.setWorkingDir(gmsDevsiteJavadoc);
execSpec.commandLine(
project.getRootProject().file("buildSrc").getPath()
+ "/gms_transform.sh");
});

// Tidy
String tidyBinary = System.getProperty("tidyBinaryPath", null);
String tidyConfig = System.getProperty("tidyConfigPath", null);
if (tidyBinary != null && tidyConfig != null) {
for (File dir :
ImmutableList.of(
firebaseDevsiteJavadoc, gmsDevsiteJavadoc)) {
try {
Files.walk(dir.toPath())
.filter(
p ->
p.toFile().isFile()
&& p.toString().endsWith(".html"))
.forEach(
p -> {
project.exec(
execSpec -> {
System.out.println("Tidying " + p);
execSpec.setIgnoreExitValue(true);
execSpec.commandLine(
tidyBinary, "-config", tidyConfig, p);
});
});
} catch (IOException e) {
throw new GradleException("Directory walk failed.", e);
}
}
}
});
});

Zip assembleFirebaseJavadocZip =
project
.getTasks()
.create(
"assembleFirebaseJavadocZip",
Zip.class,
zip -> {
zip.dependsOn(prepareJavadocs);
zip.getDestinationDirectory().set(project.getBuildDir());
zip.getArchiveFileName().set("firebase-javadoc.zip");
zip.from(firebaseDevsiteJavadoc);
zip.include("**/*");
});

Zip assembleGmsJavadocZip =
project
.getTasks()
.create(
"assembleGmsJavadocZip",
Zip.class,
zip -> {
zip.dependsOn(prepareJavadocs);
zip.getDestinationDirectory().set(project.getBuildDir());
zip.getArchiveFileName().set("gms-javadoc.zip");
zip.from(gmsDevsiteJavadoc);
zip.include("**/*");
});

if (releaseJavadocs) {
firebasePublish.dependsOn(assembleFirebaseJavadocZip, assembleGmsJavadocZip);
}
});
}
}