Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor: Update dependencies, migrate to korlibs, and improve build #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
BobbyESP wants to merge 3 commits into adamint:main
base: main
Choose a base branch
Loading
from BobbyESP:main
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor: Update dependencies, migrate to korlibs, and improve build
- Migrate to `korlibs` library from `soywiz` for image and crypto handling.
- Update project's dependencies to latest versions, including:
 - Kotlin to 2.1.0
 - Spotless to 6.25.0
 - Dokka to 1.9.10
 - Kotlinx.datetime to 0.5.0
 - Kotlinx.serialization to 1.6.2
 - Kotlinx.coroutines to 1.7.3
 - Ktor to 2.3.7
 - Spark to 2.9.4
 - Korlibs to 4.0.10
 - Android Spotify auth to 1.2.6
 - Android crypto to 1.1.0-alpha06
 - AndroidX compat to 1.6.1
 - Android Retrofuture to 1.7.4
- Refactor code to use `korlibs` classes and functions.
- Replace use of `com.soywiz` packages with `korlibs`.
- Update `settings.gradle.kts` to remove unnecessary logic.
- Update `build.gradle.kts` to use `libs.version.toml`.
- Update to Java 21.
- Remove use of `launch` from `korio`.
- Update Android compile SDK to 35 and minimum SDK to 23.
- Add support for `publishAllPublicationsToNexusRepositoryWithTests` task.
- Create `packForXcode` task to correctly compile and prepare for iOS compilation.
- Add explicit `jvmToolchain` versions.
- Migrate to the new kotlin `plugins` DSL.
- Use `when` instead of `if` for clarity in `settings.gradle.kts`.
- Use idiomatic Kotlin DSL wherever possible.
- Remove unused imports.
- Reorder imports by type.
- Switch from `id()` to `alias()` in `plugins` block.
- Correct plugin loading and versioning.
- Remove unused repositories.
- Migrate to using `libs.versions.toml` to declare all dependencies and plugins.
- Remove `buildscript` and unnecessary references.
- Added `applyDefaultHierarchyTemplate()` to `kotlin` block.
  • Loading branch information
BobbyESP committed Feb 28, 2025
commit 93a142491824ee4d398a1e525dcf61a47ec01c17
168 changes: 66 additions & 102 deletions build.gradle.kts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,23 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target

plugins {
kotlin("multiplatform")
alias(libs.plugins.kotlin.multiplatform)
`maven-publish`
signing
id("com.android.library")
kotlin("plugin.serialization")
id("com.diffplug.spotless") version "6.21.0"
id("com.moowork.node") version "1.3.1"
id("org.jetbrains.dokka") version "1.9.0"
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.spotless)
alias(libs.plugins.node)
alias(libs.plugins.dokka)
}

repositories {
google()
mavenCentral()
}

buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:") // resolved in settings.gradle.kts
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:") // resolved in settings.gradle.kts
}
}

// --- spotify-web-api-kotlin info ---
val libraryVersion: String = System.getenv("SPOTIFY_API_PUBLISH_VERSION") ?: "0.0.0.SNAPSHOT"
val libraryVersion = System.getenv("SPOTIFY_API_PUBLISH_VERSION") ?: "0.0.0.SNAPSHOT"

// Publishing credentials (environment variable)
val nexusUsername: String? = System.getenv("NEXUS_USERNAME")
Expand All @@ -44,20 +33,21 @@ val nexusPassword: String? = System.getenv("NEXUS_PASSWORD")
group = "com.adamratzman"
version = libraryVersion


android {
namespace = "com.adamratzman.spotify"
compileSdk = 31
compileSdk = 35

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

packaging {
resources.excludes.add("META-INF/*.md") // needed to prevent android compilation errors
}

defaultConfig {
minSdk = 23
setCompileSdkVersion(31)
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}

Expand All @@ -66,15 +56,19 @@ android {
isMinifyEnabled = false
}
}

testOptions {
this.unitTests.isReturnDefaultValues = true
unitTests.isReturnDefaultValues = true
}

sourceSets {
getByName("main").setRoot("src/androidMain")
getByName("test").setRoot("src/androidUnitTest")
}
sourceSets["main"].setRoot("src/androidMain")
sourceSets["test"].setRoot("src/androidUnitTest")
}

// invoked in kotlin closure, needs to be registered before
val dokkaJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
val dokkaJar by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "spotify-web-api-kotlin generated documentation"
from(tasks.dokkaHtml)
Expand All @@ -83,25 +77,27 @@ val dokkaJar: TaskProvider<Jar> by tasks.registering(Jar::class) {

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}

explicitApiWarning()
jvmToolchain(17)
jvmToolchain(21)

androidTarget {
compilations.all { kotlinOptions.jvmTarget = "17" }
compilations.all {
kotlinOptions.jvmTarget = "21"
}

mavenPublication { setupPom(artifactId) }

publishLibraryVariants("debug", "release")

publishLibraryVariantsGroupedByFlavor = true
}

jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "21"
}
testRuns["test"].executionTask.configure {
useJUnit()
Expand Down Expand Up @@ -157,45 +153,24 @@ kotlin {
mavenPublication { setupPom(artifactId) }
}

// !! unable to include currently due to korlibs not being available !!
/*
tvos {
binaries { framework { baseName = "spotify" } }

mavenPublication { setupPom(artifactId) }
}

watchos {
binaries { framework { baseName = "spotify" } }

mavenPublication { setupPom(artifactId) }
}*/

// Apply default hierarchy template for source sets
applyDefaultHierarchyTemplate()

sourceSets {
val kotlinxDatetimeVersion: String by project
val kotlinxSerializationVersion: String by project
val kotlinxCoroutinesVersion: String by project
val ktorVersion: String by project

val sparkVersion: String by project
val korlibsVersion: String by project

commonMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("com.soywiz.korlibs.krypto:krypto:$korlibsVersion")
implementation("com.soywiz.korlibs.korim:korim:$korlibsVersion")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDatetimeVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
implementation(libs.kotlinx.serialization.json)
implementation(libs.ktor.client.core)
implementation(libs.korlibs.krypto)
implementation(libs.korlibs.korim)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.coroutines.core)
}
}

commonTest {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion")
implementation(libs.kotlinx.coroutines.test)
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
Expand All @@ -205,14 +180,14 @@ kotlin {
dependsOn(commonMain.get())

dependencies {
implementation("net.sourceforge.streamsupport:android-retrofuture:1.7.3")
implementation(libs.android.retrofuture)
}
}

val commonJvmLikeTest by creating {
dependencies {
implementation(kotlin("test-junit"))
implementation("com.sparkjava:spark-core:$sparkVersion")
implementation(libs.spark.core)
runtimeOnly(kotlin("reflect"))
}
}
Expand All @@ -224,20 +199,16 @@ kotlin {
jvmMain {
dependsOn(commonJvmLikeMain)

repositories {
mavenCentral()
}

dependencies {
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation(libs.ktor.client.cio)
}
}

jvmTest.get().dependsOn(commonJvmLikeTest)

jsMain {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation(libs.ktor.client.js)
implementation(kotlin("stdlib-js"))
}
}
Expand All @@ -253,19 +224,11 @@ kotlin {
androidMain {
dependsOn(commonJvmLikeMain)

repositories {
mavenCentral()
}

dependencies {
val androidSpotifyAuthVersion: String by project
val androidCryptoVersion: String by project
val androidxCompatVersion: String by project

api("com.spotify.android:auth:$androidSpotifyAuthVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("androidx.security:security-crypto:$androidCryptoVersion")
implementation("androidx.appcompat:appcompat:$androidxCompatVersion")
api(libs.android.spotify.auth)
implementation(libs.ktor.client.okhttp)
implementation(libs.android.crypto)
implementation(libs.androidx.appcompat)
}
}

Expand All @@ -274,35 +237,38 @@ kotlin {
}

// desktop targets
// as kotlin/native, they require special ktor versions
val desktopMain by creating {
dependsOn(commonMain.get())

dependencies {
implementation("io.ktor:ktor-client-curl:$ktorVersion")
implementation(libs.ktor.client.curl)
}
}

linuxMain.get().dependsOn(desktopMain)
mingwMain.get().dependsOn(desktopMain)
macosMain.get().dependsOn(desktopMain)

val desktopTest by creating { dependsOn(commonNonJvmTargetsTest) }
val desktopTest by creating {
dependsOn(commonNonJvmTargetsTest)
}

linuxTest.get().dependsOn(desktopTest)
mingwTest.get().dependsOn(desktopTest)
macosTest.get().dependsOn(desktopTest)

// darwin targets

val nativeDarwinMain by creating {
dependsOn(commonMain.get())

dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
implementation(libs.ktor.client.ios)
}
}

val nativeDarwinTest by creating { dependsOn(commonNonJvmTargetsTest) }
val nativeDarwinTest by creating {
dependsOn(commonNonJvmTargetsTest)
}

iosMain.get().dependsOn(nativeDarwinMain)
iosTest.get().dependsOn(nativeDarwinTest)
Expand Down Expand Up @@ -343,11 +309,10 @@ tasks {
}
}


val publishAllPublicationsToNexusRepositoryWithTests by registering(Task::class) {
dependsOn.add(check)
dependsOn.add("publishAllPublicationsToNexusRepository")
dependsOn.add(dokkaHtml)
register<Task>("publishAllPublicationsToNexusRepositoryWithTests") {
dependsOn(check)
dependsOn("publishAllPublicationsToNexusRepository")
dependsOn(dokkaHtml)
}

withType<Test> {
Expand All @@ -356,27 +321,30 @@ tasks {
}
}

val packForXcode by creating(Sync::class) {
register<Sync>("packForXcode") {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
dependsOn(framework.linkTaskProvider)
val targetDir = File(layout.buildDirectory.asFile.get(), "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
getByName("build").dependsOn(packForXcode)

named("build") {
dependsOn("packForXcode")
}
}

// Configure signing tasks to run before publishing
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOn(signingTasks)
}


fun MavenPublication.setupPom(publicationName: String) {
artifactId = artifactId.replace("-web", "")
artifact(dokkaJar.get()) // add javadocs to publication
Expand All @@ -400,6 +368,7 @@ fun MavenPublication.setupPom(publicationName: String) {
distribution.set("repo")
}
}

developers {
developer {
id.set("adamratzman")
Expand All @@ -410,9 +379,7 @@ fun MavenPublication.setupPom(publicationName: String) {
}
}


// --- Publishing ---

fun PublishingExtension.registerPublishing() {
publications {
val kotlinMultiplatform by getting(MavenPublication::class) {
Expand Down Expand Up @@ -445,10 +412,7 @@ val signingPassword = project.findProperty("SIGNING_PASSWORD") as? String

signing {
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(
project.findProperty("SIGNING_KEY") as? String,
project.findProperty("SIGNING_PASSWORD") as? String
)
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
}
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /