Skip to content

Create publishChangedToBuildDir task. #494

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

package com.google.firebase.gradle.plugins.publish

import com.google.firebase.gradle.plugins.ci.AffectedProjectFinder
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension
import digital.wup.android_maven_publish.AndroidMavenPublishPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.bundling.Zip
Expand Down Expand Up @@ -83,8 +85,12 @@ class PublishingPlugin implements Plugin<Project> {

def publishAllToLocal = project.task('publishAllToLocal')
def publishAllToBuildDir = project.task('publishAllToBuildDir')
def publishChangedToBuildDir = project.task('publishChangedToBuildDir')
def firebasePublish = project.task('firebasePublish')

def changedProjects =
new AffectedProjectFinder(project, changedPaths(project.rootDir), []).find()

project.getGradle().projectsEvaluated {
project.subprojects { Project sub ->
if (!sub.plugins.hasPlugin('firebase-library')) {
Expand Down Expand Up @@ -121,10 +127,27 @@ class PublishingPlugin implements Plugin<Project> {
publisher.decorate(sub, it)
}
}

// Add changed projects to publishChangedToBuildDir.
if (changedProjects.contains(sub)) {
publishChangedToBuildDir.dependsOn "$sub.path:publishMavenAarPublicationToBuildDirRepository"
def dependencies = sub.configurations.implementation.dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/implementation/releaseRuntimeClasspath/

for (def dep : dependencies) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the intent here? Why do we need to publish dependencies of the project? Also, if it is needed indeed, don't we also want to publish dependencies of dependencies recursively?

if (dep instanceof ProjectDependency) {
def task = dep.getDependencyProject()
.tasks.findByName("publishMavenAarPublicationToBuildDirRepository")
if (task != null) {
publishChangedToBuildDir.dependsOn task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to make publishChangedToBuildDir directly depend on sub's dependencies' publishMavenAarPublicationToBuildDirRepository? Shouldn't sub's publishMavenAarPublicationToBuildDirRepository already depend on it's dependencies' publishMavenAarPublicationToBuildDirRepository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how those tasks are configured. They don't publish their dependencies.

}
}
}
}

publishAllToLocal.dependsOn "$sub.path:publishMavenAarPublicationToMavenLocal"
publishAllToBuildDir.dependsOn "$sub.path:publishMavenAarPublicationToBuildDirRepository"

}

}
project.task('publishProjectsToMavenLocal') {
projectsToPublish.each { projectToPublish ->
Expand Down Expand Up @@ -155,6 +178,13 @@ class PublishingPlugin implements Plugin<Project> {
}
}

private static Set<String> changedPaths(File workDir) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaicr, we have the same git command elsewhere, can we centralize this in one place to avoid duplication?

return 'git diff --name-only --submodule=diff HEAD@{0} HEAD@{1}'
Copy link
Contributor

@yifanyang yifanyang Jun 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see if git can be run programmatically. But it is probably fine if you think this task will be invoked only on machines that has git available. Also, what is the intended diff range here? I think HEAD@{1} can be any commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It diffs head and head - 1. I copied this from the checkChanged tasks. I think this is primarily intended for Prow, as it might give misleading results locally.

.execute([], workDir)
.text
.readLines()
}

private static String getPublishTask(Project p, String repoName) {
return "${p.path}:publishMavenAarPublicationTo$repoName"
}
Expand Down