Skip to content

Commit 2083b52

Browse files
authored
[Infra] Update how we declare kotlin compiler options (#7372)
Kotlin compiler options should be specified using the kotlin block instead of the `kotlinOptions` within `android`. See https://youtrack.jetbrains.com/issue/KT-27301/Expose-compiler-flags-via-Gradle-lazy-properties and https://b.corp.google.com/issues/247544167. This applies to how the JVM target is declared. Additionally, there's a better way to declare free compiler args, in our case to forche the explicit api flag to be "strict".
1 parent 9d4553a commit 2083b52

File tree

27 files changed

+100
-103
lines changed

27 files changed

+100
-103
lines changed

appcheck/firebase-appcheck/firebase-appcheck.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
1517
plugins {
1618
id 'firebase-library'
1719
id("kotlin-android")
@@ -43,10 +45,11 @@ android {
4345
sourceCompatibility JavaVersion.VERSION_1_8
4446
targetCompatibility JavaVersion.VERSION_1_8
4547
}
46-
kotlinOptions { jvmTarget = "1.8" }
4748
testOptions.unitTests.includeAndroidResources = true
4849
}
4950

51+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
52+
5053
dependencies {
5154
javadocClasspath libs.autovalue.annotations
5255

encoders/firebase-encoders-json/firebase-encoders-json.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
1517
plugins {
1618
id 'firebase-library'
1719
id 'kotlin-android'
1820
}
1921

2022
firebaseLibrary {
2123
publishJavadoc = false
22-
releaseNotes {
24+
releaseNotes {
2325
enabled.set(false)
2426
}
2527
}
@@ -38,16 +40,15 @@ android {
3840
sourceCompatibility JavaVersion.VERSION_1_8
3941
targetCompatibility JavaVersion.VERSION_1_8
4042
}
41-
kotlinOptions {
42-
jvmTarget = '1.8'
43-
}
4443
testOptions {
4544
unitTests {
4645
includeAndroidResources = true
4746
}
4847
}
4948
}
5049

50+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
51+
5152
dependencies {
5253
api 'com.google.firebase:firebase-encoders:17.0.0'
5354

firebase-ai/firebase-ai.gradle.kts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@file:Suppress("UnstableApiUsage")
1818

19-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
19+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2020

2121
plugins {
2222
id("firebase-library")
@@ -55,7 +55,6 @@ android {
5555
sourceCompatibility = JavaVersion.VERSION_1_8
5656
targetCompatibility = JavaVersion.VERSION_1_8
5757
}
58-
kotlinOptions { jvmTarget = "1.8" }
5958
testOptions {
6059
targetSdk = targetSdkVersion
6160
unitTests {
@@ -73,18 +72,9 @@ android {
7372
}
7473
}
7574

76-
// Enable Kotlin "Explicit API Mode". This causes the Kotlin compiler to fail if any
77-
// classes, methods, or properties have implicit `public` visibility. This check helps
78-
// avoid accidentally leaking elements into the public API, requiring that any public
79-
// element be explicitly declared as `public`.
80-
// https://github.com/Kotlin/KEEP/blob/master/proposals/explicit-api-mode.md
81-
// https://chao2zhang.medium.com/explicit-api-mode-for-kotlin-on-android-b8264fdd76d1
82-
tasks.withType<KotlinCompile>().all {
83-
if (!name.contains("test", ignoreCase = true)) {
84-
if (!kotlinOptions.freeCompilerArgs.contains("-Xexplicit-api=strict")) {
85-
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict"
86-
}
87-
}
75+
kotlin {
76+
compilerOptions { jvmTarget = JvmTarget.JVM_1_8 }
77+
explicitApi()
8878
}
8979

9080
dependencies {

firebase-appdistribution-api/firebase-appdistribution-api.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
1517
plugins {
1618
id 'firebase-library'
1719
id("kotlin-android")
@@ -41,16 +43,15 @@ android {
4143
sourceCompatibility JavaVersion.VERSION_1_8
4244
targetCompatibility JavaVersion.VERSION_1_8
4345
}
44-
kotlinOptions {
45-
jvmTarget = '1.8'
46-
}
4746
testOptions {
4847
unitTests {
4948
includeAndroidResources = true
5049
}
5150
}
5251
}
5352

53+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
54+
5455
dependencies {
5556
api libs.playservices.tasks
5657
api(libs.firebase.common)

firebase-appdistribution/test-app/test-app.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ android {
6868
sourceCompatibility JavaVersion.VERSION_1_8
6969
targetCompatibility JavaVersion.VERSION_1_8
7070
}
71-
kotlinOptions {
72-
jvmTarget = '1.8'
73-
}
7471
}
7572

73+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
74+
7675
dependencies {
7776
// TODO(rachelprince): Add flag to build with public version of SDK
7877
println("Building with HEAD version ':firebase-appdistribution' of SDK")

firebase-common/firebase-common.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
1517
plugins {
1618
id("firebase-library")
1719
id("kotlin-android")
@@ -44,14 +46,15 @@ android {
4446
sourceCompatibility = JavaVersion.VERSION_1_8
4547
targetCompatibility = JavaVersion.VERSION_1_8
4648
}
47-
kotlinOptions { jvmTarget = "1.8" }
4849
testOptions {
4950
targetSdk = targetSdkVersion
5051
unitTests { isIncludeAndroidResources = true }
5152
}
5253
lint { targetSdk = targetSdkVersion }
5354
}
5455

56+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
57+
5558
dependencies {
5659
api(libs.kotlin.coroutines.tasks)
5760

firebase-config/bandwagoner/bandwagoner.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
18+
1719
apply plugin: 'com.android.application'
1820
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
1921
apply plugin: 'org.jetbrains.kotlin.android'
@@ -58,11 +60,10 @@ android {
5860
sourceCompatibility JavaVersion.VERSION_1_8
5961
targetCompatibility JavaVersion.VERSION_1_8
6062
}
61-
kotlinOptions {
62-
jvmTarget = '1.8'
63-
}
6463
}
6564

65+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
66+
6667
firebaseTestLab {
6768
device 'model=panther,version=33,locale=en,orientation=portrait'
6869
}

firebase-config/firebase-config.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
18+
1719
plugins {
1820
id("firebase-library")
1921
id("kotlin-android")
@@ -49,15 +51,15 @@ android {
4951
targetCompatibility = JavaVersion.VERSION_1_8
5052
}
5153

52-
kotlinOptions { jvmTarget = "1.8" }
53-
5454
testOptions {
5555
targetSdk = targetSdkVersion
5656
unitTests { isIncludeAndroidResources = true }
5757
}
5858
lint { targetSdk = targetSdkVersion }
5959
}
6060

61+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
62+
6163
dependencies {
6264
// Firebase
6365
api("com.google.firebase:firebase-config-interop:16.0.1")

firebase-config/test-app/test-app.gradle.kts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
@file:Suppress("DEPRECATION") // App projects should still use FirebaseTestLabPlugin.
2-
3-
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
4-
52
/*
63
* Copyright 2023 Google LLC
74
*
@@ -18,6 +15,9 @@ import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
1815
* limitations under the License.
1916
*/
2017

18+
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
19+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
20+
2121
plugins {
2222
id("com.android.application")
2323
id("org.jetbrains.kotlin.android")
@@ -47,9 +47,10 @@ android {
4747
sourceCompatibility = JavaVersion.VERSION_1_8
4848
targetCompatibility = JavaVersion.VERSION_1_8
4949
}
50-
kotlinOptions { jvmTarget = "1.8" }
5150
}
5251

52+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
53+
5354
dependencies {
5455
implementation(project(":firebase-crashlytics")) {
5556
exclude(group = "com.google.firebase", module = "firebase-config-interop")

firebase-crashlytics/firebase-crashlytics.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
1517
plugins {
1618
id 'firebase-library'
1719
id("kotlin-android")
@@ -56,11 +58,10 @@ android {
5658
sourceCompatibility JavaVersion.VERSION_1_8
5759
targetCompatibility JavaVersion.VERSION_1_8
5860
}
59-
kotlinOptions {
60-
jvmTarget = '1.8'
61-
}
6261
}
6362

63+
kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }
64+
6465
thirdPartyLicenses {
6566
add 'Tape', "${projectDir}/third_party_licenses/tape/LICENSE"
6667
}

0 commit comments

Comments
 (0)