Skip to content

Commit d08e208

Browse files
davidmotsonDavid Motsonashvili
andauthored
Add deep transitive projects to release (#5331)
Co-authored-by: David Motsonashvili <[email protected]>
1 parent d4a56bb commit d08e208

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

buildSrc/src/main/java/com/google/firebase/gradle/plugins/PublishingPlugin.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,34 @@ abstract class PublishingPlugin : Plugin<Project> {
219219

220220
if (projectsToPublish == null) return null
221221

222-
val projectNames = projectsToPublish.split(",")
222+
val publishingProjects =
223+
allFirebaseLibraries.filter { it.artifactId.get() in projectsToPublish.split(",") }
223224

225+
val librariesToRelease = getDeepTransitiveReleases(publishingProjects, libraryGroups)
226+
227+
return ReleaseMetadata(librariesToRelease, releaseName)
228+
}
229+
230+
/**
231+
* Finds all transitive libraries that need to be released so that the input list of project names
232+
* can be released. This includes all project level dependencies, and anything in the same library
233+
* group.
234+
*/
235+
private tailrec fun getDeepTransitiveReleases(
236+
inputProjects: List<FirebaseLibraryExtension>,
237+
libraryGroups: Map<String, List<FirebaseLibraryExtension>>
238+
): List<FirebaseLibraryExtension> {
224239
val libraryGroupsToRelease =
225-
allFirebaseLibraries
226-
.filter { it.artifactId.get() in projectNames }
240+
inputProjects
241+
.flatMap { it.resolveProjectLevelDependencies() + it }
227242
.map { it.libraryGroupName }
228-
val librariesToRelease =
243+
val projectsToRelease =
229244
libraryGroups
230245
.filterKeys { it in libraryGroupsToRelease }
231246
.flatMap { it.value }
232247
.distinctBy { it.artifactId.get() }
233-
return ReleaseMetadata(librariesToRelease, releaseName)
248+
return if (inputProjects == projectsToRelease) inputProjects
249+
else getDeepTransitiveReleases(projectsToRelease, libraryGroups)
234250
}
235251

236252
private fun releaseMetadataFromReleaseConfig(

buildSrc/src/test/kotlin/com/google/firebase/gradle/plugins/PublishingPluginTests.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,27 @@ class PublishingPluginTests {
113113
Project(name = "childProject2", version = "0.9", projectDependencies = setOf(project1))
114114

115115
withProjects(project1, project2)
116-
publishAndFail(project2)
116+
publish(project2)
117+
118+
project1.pomOrNull().shouldNotBeNull()
119+
project2.pom.dependencies shouldHaveSingleElement project1.toArtifact()
120+
}
121+
}
122+
123+
@Test
124+
fun `Publish with very transitive dependency`() {
125+
with(controller) {
126+
val project1 = Project(name = "childProject1", version = "1.0", libraryGroup = "libraryGroup")
127+
val project2 =
128+
Project(name = "childProject2", version = "0.9", projectDependencies = setOf(project1))
129+
val project3 = Project(name = "childProject3", version = "1.0", libraryGroup = "libraryGroup")
130+
131+
withProjects(project1, project2, project3)
132+
publish(project2)
133+
134+
project1.pomOrNull().shouldNotBeNull()
135+
project3.pomOrNull().shouldNotBeNull()
136+
project2.pom.dependencies shouldHaveSingleElement project1.toArtifact()
117137
}
118138
}
119139

0 commit comments

Comments
 (0)