1- import org.gradle.kotlin.dsl.distribution
21import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
32import org.jetbrains.kotlin.gradle.dsl.JvmTarget
43import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
54import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
6- import kotlin.text.set
5+ import utils.TargetPlatform
6+ import utils.supportsApple
7+ import utils.toTargetPlatforms
78
89/*
910 * Copyright (c) 2023 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
1011 */
1112
1213version = project.property(" firebase-analytics.version" ) as String
14+ val supportedPlatforms = (project.property(" firebase-analytics.supportedTargets" ) as String ).toTargetPlatforms()
1315
1416plugins {
1517 id(" com.android.library" )
@@ -19,36 +21,36 @@ plugins {
1921 alias(libs.plugins.publish)
2022}
2123
22- android {
23- val minSdkVersion: Int by project
24- val compileSdkVersion: Int by project
24+ if (supportedPlatforms.contains(TargetPlatform .Android )) {
25+ android {
26+ val minSdkVersion: Int by project
27+ val compileSdkVersion: Int by project
2528
26- compileSdk = compileSdkVersion
27- namespace = " dev.gitlive.firebase.analytics"
29+ compileSdk = compileSdkVersion
30+ namespace = " dev.gitlive.firebase.analytics"
2831
29- defaultConfig {
30- minSdk = minSdkVersion
31- testInstrumentationRunner = " androidx.test.runner.AndroidJUnitRunner"
32- }
32+ defaultConfig {
33+ minSdk = minSdkVersion
34+ testInstrumentationRunner = " androidx.test.runner.AndroidJUnitRunner"
35+ }
3336
34- compileOptions {
35- sourceCompatibility = JavaVersion .VERSION_17
36- targetCompatibility = JavaVersion .VERSION_17
37- }
37+ compileOptions {
38+ sourceCompatibility = JavaVersion .VERSION_17
39+ targetCompatibility = JavaVersion .VERSION_17
40+ }
3841
39- testOptions.configureTestOptions(project)
40- packaging {
41- resources.pickFirsts.add(" META-INF/kotlinx-serialization-core.kotlin_module" )
42- resources.pickFirsts.add(" META-INF/AL2.0" )
43- resources.pickFirsts.add(" META-INF/LGPL2.1" )
44- }
45- lint {
46- abortOnError = false
42+ testOptions.configureTestOptions(project)
43+ packaging {
44+ resources.pickFirsts.add(" META-INF/kotlinx-serialization-core.kotlin_module" )
45+ resources.pickFirsts.add(" META-INF/AL2.0" )
46+ resources.pickFirsts.add(" META-INF/LGPL2.1" )
47+ }
48+ lint {
49+ abortOnError = false
50+ }
4751 }
4852}
4953
50- val supportAppleTarget = project.property(" skipAppleTargets" ) != " true"
51-
5254kotlin {
5355 explicitApi()
5456
@@ -69,28 +71,44 @@ kotlin {
6971 }
7072 }
7173
72- @Suppress(" OPT_IN_USAGE" )
73- androidTarget {
74- instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree .test)
75- unitTestVariant.sourceSetTree.set(KotlinSourceSetTree .test)
76- publishAllLibraryVariants()
74+ if (supportedPlatforms.contains(TargetPlatform .Android )) {
75+ @Suppress(" OPT_IN_USAGE" )
76+ androidTarget {
77+ instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree .test)
78+ unitTestVariant.sourceSetTree.set(KotlinSourceSetTree .test)
79+ publishAllLibraryVariants()
80+ }
7781 }
7882
79- jvm()
83+ if (supportedPlatforms.contains(TargetPlatform .Jvm )) {
84+ jvm()
85+ }
8086
81- if (supportAppleTarget ) {
87+ if (supportedPlatforms.contains( TargetPlatform . Ios ) ) {
8288 iosArm64()
8389 iosX64()
8490 iosSimulatorArm64()
91+ }
92+ if (supportedPlatforms.contains(TargetPlatform .Tvos )) {
8593 tvosArm64()
8694 tvosX64()
8795 tvosSimulatorArm64()
96+ }
97+ if (supportedPlatforms.contains(TargetPlatform .Macos )) {
8898 macosArm64()
8999 macosX64()
100+ }
101+ if (supportedPlatforms.supportsApple()) {
90102 cocoapods {
91- ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
92- tvos.deploymentTarget = libs.versions.tvos.deploymentTarget.get()
93- osx.deploymentTarget = libs.versions.macos.deploymentTarget.get()
103+ if (supportedPlatforms.contains(TargetPlatform .Ios )) {
104+ ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
105+ }
106+ if (supportedPlatforms.contains(TargetPlatform .Tvos )) {
107+ tvos.deploymentTarget = libs.versions.tvos.deploymentTarget.get()
108+ }
109+ if (supportedPlatforms.contains(TargetPlatform .Macos )) {
110+ osx.deploymentTarget = libs.versions.macos.deploymentTarget.get()
111+ }
94112 framework {
95113 baseName = " FirebaseAnalytics"
96114 }
@@ -102,19 +120,21 @@ kotlin {
102120 }
103121 }
104122
105- js(IR ) {
106- useCommonJs()
107- nodejs {
108- testTask {
109- useKarma {
110- useChromeHeadless()
123+ if (supportedPlatforms.contains(TargetPlatform .Js )) {
124+ js(IR ) {
125+ useCommonJs()
126+ nodejs {
127+ testTask {
128+ useKarma {
129+ useChromeHeadless()
130+ }
111131 }
112132 }
113- }
114- browser {
115- testTask {
116- useKarma {
117- useChromeHeadless()
133+ browser {
134+ testTask {
135+ useKarma {
136+ useChromeHeadless()
137+ }
118138 }
119139 }
120140 }
@@ -149,44 +169,16 @@ kotlin {
149169 }
150170 }
151171
152- getByName(" androidMain" ) {
153- dependencies {
154- api(libs.google.firebase.analytics)
172+ if (supportedPlatforms.contains(TargetPlatform .Android )) {
173+ getByName(" androidMain" ) {
174+ dependencies {
175+ api(libs.google.firebase.analytics)
176+ }
155177 }
156178 }
157179 }
158180}
159181
160- if (project.property(" firebase-analytics.skipIosTests" ) == " true" ) {
161- tasks.forEach {
162- if (it.name.contains(" ios" , true ) && it.name.contains(" test" , true )) { it.enabled = false }
163- }
164- }
165-
166- if (project.property(" firebase-analytics.skipMacosTests" ) == " true" ) {
167- tasks.forEach {
168- if (it.name.contains(" macos" , true ) && it.name.contains(" test" , true )) { it.enabled = false }
169- }
170- }
171-
172- if (project.property(" firebase-analytics.skipTvosTests" ) == " true" ) {
173- tasks.forEach {
174- if (it.name.contains(" tvos" , true ) && it.name.contains(" test" , true )) { it.enabled = false }
175- }
176- }
177-
178- if (project.property(" firebase-analytics.skipJvmTests" ) == " true" ) {
179- tasks.forEach {
180- if (it.name.contains(" jvm" , true ) && it.name.contains(" test" , true )) { it.enabled = false }
181- }
182- }
183-
184- if (project.property(" firebase-analytics.skipJsTests" ) == " true" ) {
185- tasks.forEach {
186- if (it.name.contains(" js" , true ) && it.name.contains(" test" , true )) { it.enabled = false }
187- }
188- }
189-
190182mavenPublishing {
191183 publishToMavenCentral(automaticRelease = true )
192184 signAllPublications()
0 commit comments