@@ -8,34 +8,23 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
88import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
99
1010plugins {
11- kotlin( " multiplatform" )
11+ alias(libs.plugins.kotlin. multiplatform)
1212 `maven- publish`
1313 signing
14- id( " com. android.library" )
15- kotlin( " plugin. serialization" )
16- id( " com.diffplug .spotless" ) version " 6.21.0 "
17- id( " com.moowork .node" ) version " 1.3.1 "
18- id( " org.jetbrains .dokka" ) version " 1.9.0 "
14+ alias(libs.plugins. android.library)
15+ alias(libs.plugins.kotlin. serialization)
16+ alias(libs.plugins .spotless)
17+ alias(libs.plugins .node)
18+ alias(libs.plugins .dokka)
1919}
2020
2121repositories {
2222 google()
2323 mavenCentral()
2424}
2525
26- buildscript {
27- repositories {
28- google()
29- mavenCentral()
30- }
31- dependencies {
32- classpath(" com.android.tools.build:gradle:" ) // resolved in settings.gradle.kts
33- classpath(" org.jetbrains.kotlin:kotlin-gradle-plugin:" ) // resolved in settings.gradle.kts
34- }
35- }
36-
3726// --- spotify-web-api-kotlin info ---
38- val libraryVersion: String = System .getenv(" SPOTIFY_API_PUBLISH_VERSION" ) ? : " 0.0.0.SNAPSHOT"
27+ val libraryVersion = System .getenv(" SPOTIFY_API_PUBLISH_VERSION" ) ? : " 0.0.0.SNAPSHOT"
3928
4029// Publishing credentials (environment variable)
4130val nexusUsername: String? = System .getenv(" NEXUS_USERNAME" )
@@ -44,20 +33,21 @@ val nexusPassword: String? = System.getenv("NEXUS_PASSWORD")
4433group = " com.adamratzman"
4534version = libraryVersion
4635
47-
4836android {
4937 namespace = " com.adamratzman.spotify"
50- compileSdk = 31
38+ compileSdk = 35
39+
5140 compileOptions {
52- sourceCompatibility = JavaVersion .VERSION_17
53- targetCompatibility = JavaVersion .VERSION_17
41+ sourceCompatibility = JavaVersion .VERSION_21
42+ targetCompatibility = JavaVersion .VERSION_21
5443 }
44+
5545 packaging {
5646 resources.excludes.add(" META-INF/*.md" ) // needed to prevent android compilation errors
5747 }
48+
5849 defaultConfig {
5950 minSdk = 23
60- setCompileSdkVersion(31 )
6151 testInstrumentationRunner = " android.support.test.runner.AndroidJUnitRunner"
6252 }
6353
@@ -66,15 +56,19 @@ android {
6656 isMinifyEnabled = false
6757 }
6858 }
59+
6960 testOptions {
70- this .unitTests.isReturnDefaultValues = true
61+ unitTests.isReturnDefaultValues = true
62+ }
63+
64+ sourceSets {
65+ getByName(" main" ).setRoot(" src/androidMain" )
66+ getByName(" test" ).setRoot(" src/androidUnitTest" )
7167 }
72- sourceSets[" main" ].setRoot(" src/androidMain" )
73- sourceSets[" test" ].setRoot(" src/androidUnitTest" )
7468}
7569
7670// invoked in kotlin closure, needs to be registered before
77- val dokkaJar: TaskProvider < Jar > by tasks.registering(Jar ::class ) {
71+ val dokkaJar by tasks.registering(Jar ::class ) {
7872 group = JavaBasePlugin .DOCUMENTATION_GROUP
7973 description = " spotify-web-api-kotlin generated documentation"
8074 from(tasks.dokkaHtml)
@@ -83,25 +77,27 @@ val dokkaJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
8377
8478kotlin {
8579 @OptIn(ExperimentalKotlinGradlePluginApi ::class )
86- compilerOptions {
80+ compilerOptions {
8781 freeCompilerArgs.add(" -Xexpect-actual-classes" )
8882 }
83+
8984 explicitApiWarning()
90- jvmToolchain(17 )
85+ jvmToolchain(21 )
9186
9287 androidTarget {
93- compilations.all { kotlinOptions.jvmTarget = " 17" }
88+ compilations.all {
89+ kotlinOptions.jvmTarget = " 21"
90+ }
9491
9592 mavenPublication { setupPom(artifactId) }
9693
9794 publishLibraryVariants(" debug" , " release" )
98-
9995 publishLibraryVariantsGroupedByFlavor = true
10096 }
10197
10298 jvm {
10399 compilations.all {
104- kotlinOptions.jvmTarget = " 1.8 "
100+ kotlinOptions.jvmTarget = " 21 "
105101 }
106102 testRuns[" test" ].executionTask.configure {
107103 useJUnit()
@@ -157,45 +153,24 @@ kotlin {
157153 mavenPublication { setupPom(artifactId) }
158154 }
159155
160- // !! unable to include currently due to korlibs not being available !!
161- /*
162- tvos {
163- binaries { framework { baseName = "spotify" } }
164-
165- mavenPublication { setupPom(artifactId) }
166- }
167-
168- watchos {
169- binaries { framework { baseName = "spotify" } }
170-
171- mavenPublication { setupPom(artifactId) }
172- }*/
173-
156+ // Apply default hierarchy template for source sets
174157 applyDefaultHierarchyTemplate()
175158
176159 sourceSets {
177- val kotlinxDatetimeVersion: String by project
178- val kotlinxSerializationVersion: String by project
179- val kotlinxCoroutinesVersion: String by project
180- val ktorVersion: String by project
181-
182- val sparkVersion: String by project
183- val korlibsVersion: String by project
184-
185160 commonMain {
186161 dependencies {
187- implementation(" org.jetbrains. kotlinx:kotlinx- serialization- json: $kotlinxSerializationVersion " )
188- implementation(" io .ktor:ktor- client- core: $ktorVersion " )
189- implementation(" com.soywiz. korlibs.krypto:krypto: $korlibsVersion " )
190- implementation(" com.soywiz. korlibs.korim:korim: $korlibsVersion " )
191- implementation(" org.jetbrains. kotlinx:kotlinx- datetime: $kotlinxDatetimeVersion " )
192- implementation(" org.jetbrains. kotlinx:kotlinx- coroutines- core: $kotlinxCoroutinesVersion " )
162+ implementation(libs. kotlinx. serialization. json)
163+ implementation(libs .ktor. client. core)
164+ implementation(libs. korlibs.krypto)
165+ implementation(libs. korlibs.korim)
166+ implementation(libs. kotlinx. datetime)
167+ implementation(libs. kotlinx. coroutines. core)
193168 }
194169 }
195170
196171 commonTest {
197172 dependencies {
198- implementation(" org.jetbrains. kotlinx:kotlinx- coroutines- test: $kotlinxCoroutinesVersion " )
173+ implementation(libs. kotlinx. coroutines. test)
199174 implementation(kotlin(" test-common" ))
200175 implementation(kotlin(" test-annotations-common" ))
201176 }
@@ -205,14 +180,14 @@ kotlin {
205180 dependsOn(commonMain.get())
206181
207182 dependencies {
208- implementation(" net.sourceforge.streamsupport: android-retrofuture:1.7.3 " )
183+ implementation(libs. android.retrofuture )
209184 }
210185 }
211186
212187 val commonJvmLikeTest by creating {
213188 dependencies {
214189 implementation(kotlin(" test-junit" ))
215- implementation(" com.sparkjava: spark- core: $sparkVersion " )
190+ implementation(libs. spark. core)
216191 runtimeOnly(kotlin(" reflect" ))
217192 }
218193 }
@@ -224,20 +199,16 @@ kotlin {
224199 jvmMain {
225200 dependsOn(commonJvmLikeMain)
226201
227- repositories {
228- mavenCentral()
229- }
230-
231202 dependencies {
232- implementation(" io .ktor:ktor- client- cio: $ktorVersion " )
203+ implementation(libs .ktor. client. cio)
233204 }
234205 }
235206
236207 jvmTest.get().dependsOn(commonJvmLikeTest)
237208
238209 jsMain {
239210 dependencies {
240- implementation(" io .ktor:ktor- client-js: $ktorVersion " )
211+ implementation(libs .ktor. client.js )
241212 implementation(kotlin(" stdlib-js" ))
242213 }
243214 }
@@ -253,19 +224,11 @@ kotlin {
253224 androidMain {
254225 dependsOn(commonJvmLikeMain)
255226
256- repositories {
257- mavenCentral()
258- }
259-
260227 dependencies {
261- val androidSpotifyAuthVersion: String by project
262- val androidCryptoVersion: String by project
263- val androidxCompatVersion: String by project
264-
265- api(" com.spotify.android:auth:$androidSpotifyAuthVersion " )
266- implementation(" io.ktor:ktor-client-okhttp:$ktorVersion " )
267- implementation(" androidx.security:security-crypto:$androidCryptoVersion " )
268- implementation(" androidx.appcompat:appcompat:$androidxCompatVersion " )
228+ api(libs.android.spotify.auth)
229+ implementation(libs.ktor.client.okhttp)
230+ implementation(libs.android.crypto)
231+ implementation(libs.androidx.appcompat)
269232 }
270233 }
271234
@@ -274,35 +237,38 @@ kotlin {
274237 }
275238
276239 // desktop targets
277- // as kotlin/native, they require special ktor versions
278240 val desktopMain by creating {
279241 dependsOn(commonMain.get())
280242
281243 dependencies {
282- implementation(" io .ktor:ktor- client- curl: $ktorVersion " )
244+ implementation(libs .ktor. client. curl)
283245 }
284246 }
285247
286248 linuxMain.get().dependsOn(desktopMain)
287249 mingwMain.get().dependsOn(desktopMain)
288250 macosMain.get().dependsOn(desktopMain)
289251
290- val desktopTest by creating { dependsOn(commonNonJvmTargetsTest) }
252+ val desktopTest by creating {
253+ dependsOn(commonNonJvmTargetsTest)
254+ }
255+
291256 linuxTest.get().dependsOn(desktopTest)
292257 mingwTest.get().dependsOn(desktopTest)
293258 macosTest.get().dependsOn(desktopTest)
294259
295260 // darwin targets
296-
297261 val nativeDarwinMain by creating {
298262 dependsOn(commonMain.get())
299263
300264 dependencies {
301- implementation(" io .ktor:ktor- client- ios: $ktorVersion " )
265+ implementation(libs .ktor. client. ios)
302266 }
303267 }
304268
305- val nativeDarwinTest by creating { dependsOn(commonNonJvmTargetsTest) }
269+ val nativeDarwinTest by creating {
270+ dependsOn(commonNonJvmTargetsTest)
271+ }
306272
307273 iosMain.get().dependsOn(nativeDarwinMain)
308274 iosTest.get().dependsOn(nativeDarwinTest)
@@ -343,11 +309,10 @@ tasks {
343309 }
344310 }
345311
346-
347- val publishAllPublicationsToNexusRepositoryWithTests by registering(Task ::class ) {
348- dependsOn.add(check)
349- dependsOn.add(" publishAllPublicationsToNexusRepository" )
350- dependsOn.add(dokkaHtml)
312+ register<Task >(" publishAllPublicationsToNexusRepositoryWithTests" ) {
313+ dependsOn(check)
314+ dependsOn(" publishAllPublicationsToNexusRepository" )
315+ dependsOn(dokkaHtml)
351316 }
352317
353318 withType<Test > {
@@ -356,27 +321,30 @@ tasks {
356321 }
357322 }
358323
359- val packForXcode by creating( Sync :: class ) {
324+ register< Sync >( " packForXcode " ) {
360325 group = " build"
361326 val mode = System .getenv(" CONFIGURATION" ) ? : " DEBUG"
362327 val sdkName = System .getenv(" SDK_NAME" ) ? : " iphonesimulator"
363328 val targetName = " ios" + if (sdkName.startsWith(" iphoneos" )) " Arm64" else " X64"
364329 val framework = kotlin.targets.getByName<KotlinNativeTarget >(targetName).binaries.getFramework(mode)
365330 inputs.property(" mode" , mode)
366- dependsOn(framework.linkTask )
331+ dependsOn(framework.linkTaskProvider )
367332 val targetDir = File (layout.buildDirectory.asFile.get(), " xcode-frameworks" )
368333 from({ framework.outputDirectory })
369334 into(targetDir)
370335 }
371- getByName(" build" ).dependsOn(packForXcode)
336+
337+ named(" build" ) {
338+ dependsOn(" packForXcode" )
339+ }
372340}
373341
342+ // Configure signing tasks to run before publishing
374343val signingTasks = tasks.withType<Sign >()
375344tasks.withType<AbstractPublishToMaven >().configureEach {
376345 dependsOn(signingTasks)
377346}
378347
379-
380348fun MavenPublication.setupPom (publicationName : String ) {
381349 artifactId = artifactId.replace(" -web" , " " )
382350 artifact(dokkaJar.get()) // add javadocs to publication
@@ -400,6 +368,7 @@ fun MavenPublication.setupPom(publicationName: String) {
400368 distribution.set(" repo" )
401369 }
402370 }
371+
403372 developers {
404373 developer {
405374 id.set(" adamratzman" )
@@ -410,9 +379,7 @@ fun MavenPublication.setupPom(publicationName: String) {
410379 }
411380}
412381
413-
414382// --- Publishing ---
415-
416383fun PublishingExtension.registerPublishing () {
417384 publications {
418385 val kotlinMultiplatform by getting(MavenPublication ::class ) {
@@ -445,10 +412,7 @@ val signingPassword = project.findProperty("SIGNING_PASSWORD") as? String
445412
446413signing {
447414 if (signingKey != null && signingPassword != null ) {
448- useInMemoryPgpKeys(
449- project.findProperty(" SIGNING_KEY" ) as ? String ,
450- project.findProperty(" SIGNING_PASSWORD" ) as ? String
451- )
415+ useInMemoryPgpKeys(signingKey, signingPassword)
452416 sign(publishing.publications)
453417 }
454418}
0 commit comments