Skip to content

Commit 237ac95

Browse files
authored
Enable for Kotlin Gradle dsl. (#4392)
* Enable for Kotlin Gradle dsl. Additionally migrate to using a version catalog to simplify dependency management. * Fix metalava * Address review comments
1 parent b5a821d commit 237ac95

File tree

6 files changed

+94
-65
lines changed

6 files changed

+94
-65
lines changed

build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import com.google.firebase.gradle.plugins.license.LicenseResolverPlugin
1616
import com.google.firebase.gradle.MultiProjectReleasePlugin
1717

1818
buildscript {
19-
ext.kotlinVersion = '1.7.10'
20-
ext.coroutinesVersion = '1.6.4'
19+
// TODO: remove once all sdks have migrated to version catalog
20+
ext.kotlinVersion = libs.versions.kotlin.get()
21+
ext.coroutinesVersion = libs.versions.coroutines.get()
2122

2223
repositories {
2324
google()
@@ -47,13 +48,12 @@ apply from: 'sdkProperties.gradle'
4748
apply from: "gradle/errorProne.gradle"
4849

4950
ext {
50-
playServicesVersion = '16.0.1'
51-
supportAnnotationsVersion = '28.0.0'
52-
googleTruthVersion = '1.1.2'
53-
grpcVersion = '1.50.2'
54-
robolectricVersion = '4.9'
55-
protocVersion = '3.17.3'
56-
javaliteVersion = '3.17.3'
51+
// TODO: remove once all sdks have migrated to version catalog
52+
googleTruthVersion = libs.versions.truth.get()
53+
grpcVersion = libs.versions.grpc.get()
54+
robolectricVersion = libs.versions.robolectric.get()
55+
protocVersion = libs.versions.protoc.get()
56+
javaliteVersion = libs.versions.javalite.get()
5757
}
5858

5959
apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin

firebase-common/ktx/ktx.gradle

Lines changed: 0 additions & 55 deletions
This file was deleted.

firebase-common/ktx/ktx.gradle.kts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
plugins {
16+
id("firebase-library")
17+
id("kotlin-android")
18+
}
19+
20+
firebaseLibrary {
21+
releaseWith(project(":firebase-common"))
22+
}
23+
24+
android {
25+
val targetSdkVersion : Int by rootProject
26+
val minSdkVersion : Int by rootProject
27+
compileSdk = targetSdkVersion
28+
defaultConfig {
29+
minSdk = minSdkVersion
30+
targetSdk = targetSdkVersion
31+
}
32+
sourceSets {
33+
getByName("main") {
34+
java.srcDirs("src/main/kotlin")
35+
}
36+
getByName("test") {
37+
java.srcDirs("src/test/kotlin")
38+
}
39+
}
40+
testOptions.unitTests.isIncludeAndroidResources = true
41+
}
42+
43+
dependencies {
44+
implementation(libs.kotlin.stdlib)
45+
46+
implementation(project(":firebase-annotations"))
47+
implementation(project(":firebase-common"))
48+
implementation(project(":firebase-components"))
49+
implementation(libs.androidx.annotation)
50+
51+
// We"re exposing this library as a transitive dependency so developers can
52+
// get Kotlin Coroutines support out-of-the-box for methods that return a Task
53+
api(libs.kotlin.coroutines.tasks)
54+
55+
testImplementation(libs.robolectric)
56+
testImplementation(libs.junit)
57+
testImplementation(libs.truth)
58+
testImplementation(libs.androidx.test.core)
59+
testImplementation(libs.kotlin.coroutines.test)
60+
}

gradle/libs.versions.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[versions]
2+
coroutines = "1.6.4"
3+
grpc = "1.50.2"
4+
javalite = "3.17.3"
5+
kotlin = "1.7.10"
6+
protoc = "3.17.3"
7+
robolectric = "4.9"
8+
truth = "1.1.2"
9+
10+
[libraries]
11+
androidx-annotation = { module = "androidx.annotation:annotation", version = "1.5.0" }
12+
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
13+
kotlin-coroutines-tasks = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "coroutines" }
14+
15+
# Test libs
16+
androidx-test-core = { module = "androidx.test:core", version = "1.5.0" }
17+
junit = { module = "junit:junit", version = "4.13.2" }
18+
kotlin-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
19+
robolectric = {module = "org.robolectric:robolectric", version.ref = "robolectric" }
20+
truth = { module = "com.google.truth:truth", version.ref = "truth"}

gradle/projectSettings.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ ext {
2929

3030
/** Recursively renames build scripts to ${project.name}.gradle. */
3131
renameBuildScripts = {ProjectDescriptor project ->
32-
project.buildFileName = project.parent ? "${project.name}.gradle" : 'build.gradle'
32+
def ktsFile = "${project.name}.gradle.kts"
33+
def projectFile = new File(project.projectDir, ktsFile).exists() ? ktsFile : "${project.name}.gradle"
34+
project.buildFileName = project.parent ? projectFile : 'build.gradle'
3335

3436
project.children.each {
3537
renameBuildScripts(it)

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
rootProject.name = 'com.google.firebase'
1616

17+
enableFeaturePreview("VERSION_CATALOGS")
18+
1719
//Note: do not add subprojects to this file. Instead add them to subprojects.gradle
1820

1921
apply from: 'gradle/projectSettings.gradle'

0 commit comments

Comments
 (0)