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..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 @@ -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.latestNonAlphaVersionOrNull("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.latestNonAlphaVersionOrNull("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. * @@ -403,6 +434,11 @@ class GMavenServiceController( return findFirebaseArtifact(groupId, artifactId)?.latestVersion } + /** @see GMavenService.latestNonAlphaVersionOrNull */ + 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 +591,7 @@ data class GroupIndexArtifact( val artifactId: String, val versions: List, val latestVersion: String = versions.last(), + val latestNonAlphaVersion: String? = versions.findLast { !it.contains("alpha") }, ) { /**