From b029172ebbe9f3e8c1f5a0722fe8a9aacecd55ec Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 15 Aug 2025 11:23:34 -0700 Subject: [PATCH 1/4] add support for fetching non-alpha artifacts to fix BoM generation --- .../GenerateTutorialBundleTask.kt | 2 +- .../gradle/plugins/services/GmavenService.kt | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/plugins/src/main/java/com/google/firebase/gradle/bomgenerator/GenerateTutorialBundleTask.kt b/plugins/src/main/java/com/google/firebase/gradle/bomgenerator/GenerateTutorialBundleTask.kt index c73389cbaa6..0676b2ba386 100644 --- a/plugins/src/main/java/com/google/firebase/gradle/bomgenerator/GenerateTutorialBundleTask.kt +++ b/plugins/src/main/java/com/google/firebase/gradle/bomgenerator/GenerateTutorialBundleTask.kt @@ -195,7 +195,7 @@ abstract class GenerateTutorialBundleTask : DefaultTask() { } else { logger.info("Fetching the latest version for an artifact: $fullArtifactName") - return gmaven.get().latestVersionOrNull(fullArtifactName) + return gmaven.get().latestNonAlphaVersionOrNull(fullArtifactName) ?: throw RuntimeException( "An artifact required for the tutorial bundle is missing from gmaven: $fullArtifactName" ) diff --git a/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt b/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt index b6093225f65..9f1813d048f 100644 --- a/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt +++ b/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt @@ -150,6 +150,37 @@ abstract class GMavenService : BuildService { fun latestVersionOrNull(groupId: String, artifactId: String) = controller.latestVersionOrNull(groupId, artifactId) + /** + * Gets the latest non-alpha version of the artifact that has been uploaded to GMaven, if any. + * + * ``` + * gmaven.latestVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1" + * ``` + * + * @param groupId The group to search under. + * @param artifactId The artifact to search for. + * @return The latest released version as a string, or null if the artifact couldn't be found. + * @see latestVersion + */ + fun latestNonAlphaVersionOrNull(groupId: String, artifactId: String) = + controller.latestNonAlphaVersionOrNull(groupId, artifactId) + + /** + * Gets the latest non-alpha version of the artifact that has been uploaded to GMaven, if any. + * + * ``` + * gmaven.latestVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1" + * ``` + * + * @param fullArtifactName The artifact to search for, represented as "groupId:artifactId". + * @return The latest released version as a string, or null if the artifact couldn't be found. + * @see latestVersion + */ + fun latestNonAlphaVersionOrNull(fullArtifactName: String): String? { + val (groupId, artifactId) = fullArtifactName.split(":") + return latestNonAlphaVersionOrNull(groupId, artifactId) + } + /** * Gets the latest version of the artifact that has been uploaded to GMaven, if any. * @@ -184,6 +215,24 @@ abstract class GMavenService : BuildService { "Failed to get the latest version from gmaven for \'$artifactId\'. Has it been published?" ) + /** + * Gets the latest non-alpha version of the artifact that has been uploaded to GMaven. + * + * ``` + * gmaven.latestVersion("com.google.firebase", "firebase-components") // "18.0.1" + * ``` + * + * @param groupId The group to search under. + * @param artifactId The artifact to search for. + * @return The latest released version as a string. + * @see latestNonAlphaVersionOrNull + */ + fun latestNonAlphaVersion(groupId: String, artifactId: String) = + latestVersionOrNull(groupId, artifactId) + ?: throw RuntimeException( + "Failed to get the latest version from gmaven for \'$artifactId\'. Has it been published?" + ) + /** * Checks if an artifact has been published to GMaven. * @@ -403,6 +452,11 @@ class GMavenServiceController( return findFirebaseArtifact(groupId, artifactId)?.latestVersion } + /** @see GMavenService.latestVersionOrNull */ + fun latestNonAlphaVersionOrNull(groupId: String, artifactId: String): String? { + return findFirebaseArtifact(groupId, artifactId)?.latestNonAlphaVersion + } + /** @see GMavenService.hasReleasedArtifact */ fun hasReleasedArtifact(groupId: String, artifactId: String): Boolean { return findFirebaseArtifact(groupId, artifactId) !== null @@ -555,6 +609,7 @@ data class GroupIndexArtifact( val artifactId: String, val versions: List, val latestVersion: String = versions.last(), + val latestNonAlphaVersion: String = versions.last { !it.contains("alpha") } ) { /** From 3086d72e72252f8732146a990e6471ac40765b4e Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 15 Aug 2025 11:32:27 -0700 Subject: [PATCH 2/4] fixes for comments, and removing an extraneous API --- .../gradle/plugins/services/GmavenService.kt | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt b/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt index 9f1813d048f..a09dfe502e9 100644 --- a/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt +++ b/plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt @@ -154,7 +154,7 @@ abstract class GMavenService : BuildService { * Gets the latest non-alpha version of the artifact that has been uploaded to GMaven, if any. * * ``` - * gmaven.latestVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1" + * gmaven.latestNonAlphaVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1" * ``` * * @param groupId The group to search under. @@ -169,7 +169,7 @@ abstract class GMavenService : BuildService { * Gets the latest non-alpha version of the artifact that has been uploaded to GMaven, if any. * * ``` - * gmaven.latestVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1" + * gmaven.latestNonAlphaVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1" * ``` * * @param fullArtifactName The artifact to search for, represented as "groupId:artifactId". @@ -215,24 +215,6 @@ abstract class GMavenService : BuildService { "Failed to get the latest version from gmaven for \'$artifactId\'. Has it been published?" ) - /** - * Gets the latest non-alpha version of the artifact that has been uploaded to GMaven. - * - * ``` - * gmaven.latestVersion("com.google.firebase", "firebase-components") // "18.0.1" - * ``` - * - * @param groupId The group to search under. - * @param artifactId The artifact to search for. - * @return The latest released version as a string. - * @see latestNonAlphaVersionOrNull - */ - fun latestNonAlphaVersion(groupId: String, artifactId: String) = - latestVersionOrNull(groupId, artifactId) - ?: throw RuntimeException( - "Failed to get the latest version from gmaven for \'$artifactId\'. Has it been published?" - ) - /** * Checks if an artifact has been published to GMaven. * @@ -452,7 +434,7 @@ class GMavenServiceController( return findFirebaseArtifact(groupId, artifactId)?.latestVersion } - /** @see GMavenService.latestVersionOrNull */ + /** @see GMavenService.latestNonAlphaVersionOrNull */ fun latestNonAlphaVersionOrNull(groupId: String, artifactId: String): String? { return findFirebaseArtifact(groupId, artifactId)?.latestNonAlphaVersion } @@ -609,7 +591,7 @@ data class GroupIndexArtifact( val artifactId: String, val versions: List, val latestVersion: String = versions.last(), - val latestNonAlphaVersion: String = versions.last { !it.contains("alpha") } + val latestNonAlphaVersion: String? = versions.findLast { !it.contains("alpha") }, ) { /** From f25809a178cdfcc96dd9cc32fbb1ffb4c6807e4e Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 15 Aug 2025 11:48:57 -0700 Subject: [PATCH 3/4] fix tests --- .../firebase/gradle/plugins/GenerateTutorialBundleTests.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt b/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt index ea744bb2a27..74d52dbaf08 100644 --- a/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt +++ b/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt @@ -242,7 +242,7 @@ class GenerateTutorialBundleTests : FunSpec() { @Test fun `throws an error if an unreleased artifact is used`() { shouldThrowSubstring("missing from gmaven", "com.google.firebase:firebase-auth") { - every { service.latestVersionOrNull(any()) } answers { null } + every { service.latestNonAlphaVersionOrNull(any()) } answers { null } val task = makeTask { firebaseArtifacts.set(listOf("com.google.firebase:firebase-auth")) } @@ -293,7 +293,7 @@ class GenerateTutorialBundleTests : FunSpec() { val (groupId, artifactId, version) = it.split(":") "$groupId:$artifactId" to version } - .onEach { entry -> every { service.latestVersionOrNull(entry.key) } answers { entry.value } } + .onEach { entry -> every { service.latestNonAlphaVersionOrNull(entry.key) } answers { entry.value } } } private fun makeTutorial( From 5eac4b26bb099ceae36d78048002846c3bd9ba8b Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 15 Aug 2025 11:55:14 -0700 Subject: [PATCH 4/4] format --- .../firebase/gradle/plugins/GenerateTutorialBundleTests.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt b/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt index 74d52dbaf08..3a2fe06ca30 100644 --- a/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt +++ b/plugins/src/test/kotlin/com/google/firebase/gradle/plugins/GenerateTutorialBundleTests.kt @@ -293,7 +293,9 @@ class GenerateTutorialBundleTests : FunSpec() { val (groupId, artifactId, version) = it.split(":") "$groupId:$artifactId" to version } - .onEach { entry -> every { service.latestNonAlphaVersionOrNull(entry.key) } answers { entry.value } } + .onEach { entry -> + every { service.latestNonAlphaVersionOrNull(entry.key) } answers { entry.value } + } } private fun makeTutorial(