Skip to content

Commit 5bb0bb0

Browse files
authored
Update dependencies (#7)
* First drop to update dependencies Includes Kotlin 2.1.20 * Re-enable sample apps * Re-enable detekt * Re-enable gradleVersionsPlugin and update more deps * Update gradle wrapper to latest * Enable dokka v2 * Update build script * Update java toolchain
1 parent a42ae79 commit 5bb0bb0

File tree

55 files changed

+887
-617
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+887
-617
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ ij_kotlin_wrap_expression_body_functions = 1
4242
indent_style = space
4343
indent_size = 4
4444
trim_trailing_whitespace = false
45+
max_line_length = 80

.github/workflows/build.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,28 @@ jobs:
1515
name: "Validation"
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
19-
- uses: gradle/wrapper-validation-action@v1
18+
- uses: actions/checkout@v4
19+
- uses: gradle/actions/wrapper-validation@v3
2020

2121
build:
2222
needs: [validation]
2323
runs-on: macOS-latest
2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v4
26+
- uses: actions/setup-java@v4
27+
with:
28+
distribution: 'zulu'
29+
java-version: '17'
30+
cache: 'gradle'
31+
32+
- name: Setup Gradle
33+
uses: gradle/actions/setup-gradle@v4
2634

27-
- name: Set up JDK 1.8
28-
uses: actions/setup-java@v1
35+
- name: konan cache
36+
uses: actions/cache@v4
2937
with:
30-
java-version: 1.8
38+
path: ~/.konan
39+
key: ${{ runner.os }}-konan
3140

3241
- name: Check
3342
run: ./gradlew check
@@ -43,9 +52,5 @@ jobs:
4352
if: startsWith(github.ref, 'refs/tags/')
4453

4554
- name: Upload tag
46-
run: ./gradlew publish --no-daemon --no-parallel -Psigning.secretKeyRingFile=$(echo ~/.gradle/sonatype-appmattus-keys.gpg)
47-
if: startsWith(github.ref, 'refs/tags/')
48-
49-
- name: Close and release tag
50-
run: ./gradlew closeAndReleaseRepository
55+
run: ./gradlew publishAllPublicationsToMavenCentral -Psigning.secretKeyRingFile=$(echo ~/.gradle/sonatype-appmattus-keys.gpg)
5156
if: startsWith(github.ref, 'refs/tags/')

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,5 @@ fabric.properties
300300
!swiftlint-wrapper.jar
301301

302302
# End of https://www.toptal.com/developers/gitignore/api/android,androidstudio,xcode,swift,kotlin
303+
304+
.kotlin

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ distinguish between cellular vs WiFi connection.
2323
![badge][badge-android]
2424
![badge][badge-ios]
2525

26-
[ignore-test](ignore-test/README.md): Annotations to ignore tests from
27-
specific platforms.
26+
[ignore-ios](ignore-ios/README.md): Annotations to ignore iOS tests.
27+
![badge][badge-android]
28+
![badge][badge-ios]
29+
![badge][badge-jvm]
30+
31+
[ignore-junit](ignore-junit/README.md): Annotations to ignore JUnit 4 tests.
32+
![badge][badge-android]
33+
![badge][badge-ios]
34+
![badge][badge-jvm]
35+
36+
[ignore-junit5](ignore-junit5/README.md): Annotations to ignore JUnit 5 tests.
2837
![badge][badge-android]
2938
![badge][badge-ios]
3039
![badge][badge-jvm]

battery/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ commonMain {
1717
}
1818
```
1919

20-
Create an instance of Battery
20+
Create an instance of Battery
2121

2222
To create a hash first create a digest with `Digest.create` providing the name
2323
of the hash you wish to use, then update with `update` and create the hash with
@@ -35,8 +35,6 @@ val hash: ByteArray = digest.digest()
3535
digest.digest(byteArray)
3636
```
3737

38-
39-
4038
---
4139

4240
Inspired by the Flutter [battery](https://pub.dev/packages/battery) package.

battery/build.gradle.kts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Appmattus Limited
2+
* Copyright 2021-2025 Appmattus Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,49 +14,52 @@
1414
* limitations under the License.
1515
*/
1616

17-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
18-
1917
plugins {
20-
kotlin("multiplatform")
2118
id("com.android.library")
22-
id("com.vanniktech.maven.publish")
23-
id("org.jetbrains.dokka")
19+
kotlin("multiplatform")
20+
alias(libs.plugins.gradleMavenPublishPlugin)
21+
alias(libs.plugins.dokkaPlugin)
2422
}
2523

2624
kotlin {
27-
android()
28-
ios()
25+
androidTarget()
2926

30-
sourceSets {
31-
val commonMain by getting {
32-
dependencies {
33-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") {
34-
version {
35-
strictly(Versions.coroutinesNative)
36-
}
37-
}
38-
}
27+
iosX64()
28+
iosArm64()
29+
iosSimulatorArm64()
30+
31+
listOf(
32+
iosX64(),
33+
iosArm64(),
34+
iosSimulatorArm64()
35+
).forEach { iosTarget ->
36+
iosTarget.binaries.framework {
37+
baseName = "multiplatformutils-battery"
38+
isStatic = true
3939
}
40-
val commonTest by getting
41-
val androidMain by getting {
42-
dependencies {
43-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}")
44-
}
40+
}
41+
42+
// Apply the default hierarchy again. It'll create, for example, the iosMain source set:
43+
applyDefaultHierarchyTemplate()
44+
45+
sourceSets {
46+
commonMain.dependencies {
47+
implementation(libs.kotlinx.coroutines)
4548
}
46-
val androidTest by getting
47-
val iosMain by getting
48-
val iosTest by getting
49+
}
50+
51+
compilerOptions {
52+
jvmToolchain(11)
53+
freeCompilerArgs.add("-Xexpect-actual-classes")
4954
}
5055
}
5156

5257
android {
53-
compileSdkVersion(30)
54-
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
58+
namespace = "com.appmattus.multiplatformutils.battery"
59+
compileSdk = 35
60+
5561
defaultConfig {
56-
minSdkVersion(21)
57-
targetSdkVersion(30)
58-
versionCode = 1
59-
versionName = "1.0"
62+
minSdk = 21
6063
}
6164
buildTypes {
6265
getByName("release") {
@@ -65,9 +68,7 @@ android {
6568
}
6669

6770
compileOptions {
68-
sourceCompatibility = JavaVersion.VERSION_1_8
69-
targetCompatibility = JavaVersion.VERSION_1_8
71+
sourceCompatibility = JavaVersion.VERSION_11
72+
targetCompatibility = JavaVersion.VERSION_11
7073
}
7174
}
72-
73-
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() }

battery/src/androidMain/AndroidManifest.xml

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

battery/src/androidMain/kotlin/com/appmattus/battery/Battery.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Appmattus Limited
2+
* Copyright 2021-2025 Appmattus Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,12 +18,9 @@ package com.appmattus.battery
1818

1919
import android.content.BroadcastReceiver
2020
import android.content.Context
21-
import android.content.ContextWrapper
2221
import android.content.Intent
2322
import android.content.IntentFilter
2423
import android.os.BatteryManager
25-
import android.os.Build.VERSION
26-
import android.os.Build.VERSION_CODES
2724
import com.appmattus.battery.ChargingStatus.Status.Charging
2825
import com.appmattus.battery.ChargingStatus.Status.Discharging
2926
import com.appmattus.battery.ChargingStatus.Status.Full
@@ -35,18 +32,11 @@ import kotlinx.coroutines.flow.callbackFlow
3532
actual class Battery(private val context: Context) {
3633

3734
actual val batteryLevel: Int
38-
get() = if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
35+
get() {
3936
val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
40-
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
41-
} else {
42-
val intent = ContextWrapper(context)
43-
.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))!!
44-
@Suppress("MagicNumber")
45-
(intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100 /
46-
intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1))
37+
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
4738
}
4839

49-
@Suppress("EXPERIMENTAL_API_USAGE")
5040
actual val chargingStatus: Flow<ChargingStatus>
5141
get() = callbackFlow {
5242
val receiver = object : BroadcastReceiver() {

battery/src/iosMain/kotlin/com/appmattus/battery/Battery.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Appmattus Limited
2+
* Copyright 2021-2025 Appmattus Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,6 @@ actual class Battery {
4141
}
4242
}
4343

44-
@Suppress("EXPERIMENTAL_API_USAGE")
4544
actual val chargingStatus: Flow<ChargingStatus>
4645
get() = callbackFlow {
4746
UIDevice.currentDevice.batteryMonitoringEnabled = true
@@ -63,13 +62,18 @@ actual class Battery {
6362
}
6463

6564
companion object {
65+
@Suppress("REDUNDANT_ELSE_IN_WHEN", "KotlinRedundantDiagnosticSuppress")
6666
private val UIDeviceBatteryState.asChargingStatus
67-
get() = if (NSProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != null) ChargingStatus(Full) else when (this) {
68-
UIDeviceBatteryState.UIDeviceBatteryStateCharging -> ChargingStatus(Charging)
69-
UIDeviceBatteryState.UIDeviceBatteryStateFull -> ChargingStatus(Full)
70-
UIDeviceBatteryState.UIDeviceBatteryStateUnplugged -> ChargingStatus(Discharging)
71-
UIDeviceBatteryState.UIDeviceBatteryStateUnknown -> ChargingStatus(Unavailable)
72-
else -> ChargingStatus(Unavailable)
67+
get() = if (NSProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != null) {
68+
ChargingStatus(Full)
69+
} else {
70+
when (this) {
71+
UIDeviceBatteryState.UIDeviceBatteryStateCharging -> ChargingStatus(Charging)
72+
UIDeviceBatteryState.UIDeviceBatteryStateFull -> ChargingStatus(Full)
73+
UIDeviceBatteryState.UIDeviceBatteryStateUnplugged -> ChargingStatus(Discharging)
74+
UIDeviceBatteryState.UIDeviceBatteryStateUnknown -> ChargingStatus(Unavailable)
75+
else -> ChargingStatus(Unavailable)
76+
}
7377
}
7478

7579
private const val BATTERY_MAX_VALUE = 100

build.gradle.kts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Appmattus Limited
2+
* Copyright 2021-2025 Appmattus Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,12 +15,13 @@
1515
*/
1616

1717
import io.gitlab.arturbosch.detekt.Detekt
18+
import java.time.ZonedDateTime
1819

1920
plugins {
20-
id("io.gitlab.arturbosch.detekt") version Versions.detektGradlePlugin
21-
id("com.appmattus.markdown") version Versions.markdownlintGradlePlugin
22-
id("com.vanniktech.maven.publish") version Versions.gradleMavenPublishPlugin apply false
23-
id("org.jetbrains.dokka") version Versions.dokkaPlugin
21+
alias(libs.plugins.detektGradlePlugin)
22+
alias(libs.plugins.markdownlintGradlePlugin)
23+
alias(libs.plugins.gradleMavenPublishPlugin) apply false
24+
alias(libs.plugins.dokkaPlugin)
2425
}
2526

2627
buildscript {
@@ -30,10 +31,10 @@ buildscript {
3031
mavenCentral()
3132
}
3233
dependencies {
33-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
34-
classpath("com.android.tools.build:gradle:${Versions.androidGradlePlugin}")
35-
classpath("com.google.dagger:hilt-android-gradle-plugin:${Versions.Google.dagger}")
36-
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.AndroidX.navigation}")
34+
classpath(libs.buildscript.android)
35+
classpath(libs.buildscript.kotlin)
36+
classpath(libs.buildscript.hilt)
37+
classpath(libs.buildscript.safeargs)
3738
}
3839
}
3940

@@ -44,26 +45,26 @@ allprojects {
4445
gradlePluginPortal()
4546
google()
4647
mavenCentral()
47-
maven(url = "https://kotlin.bintray.com/kotlinx/")
48+
maven { url = uri("https://jitpack.io") }
4849
}
4950
}
5051

5152
dependencies {
52-
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.detektGradlePlugin}")
53+
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${libs.versions.detektGradlePlugin.get()}")
5354
}
5455

5556
tasks.withType<Detekt> {
56-
jvmTarget = "1.8"
57+
jvmTarget = "11"
5758
}
5859

5960
detekt {
60-
input = files(subprojects.map { File(it.projectDir, "src") })
61+
source.setFrom(files(subprojects.map { File(it.projectDir, "src") }))
6162

6263
buildUponDefaultConfig = true
6364

6465
autoCorrect = true
6566

66-
config = files("detekt-config.yml")
67+
config.setFrom(files("detekt-config.yml"))
6768
}
6869

6970
tasks.maybeCreate("check").dependsOn(tasks.named("detekt"))
@@ -74,20 +75,24 @@ allprojects {
7475
version = System.getenv("GITHUB_REF")?.substring(10) ?: System.getProperty("GITHUB_REF")?.substring(10) ?: "unknown"
7576

7677
plugins.withType<org.jetbrains.dokka.gradle.DokkaPlugin> {
77-
tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
78+
dokka {
7879
dokkaSourceSets {
7980
configureEach {
80-
if (name.startsWith("ios")) {
81-
displayName.set("ios")
82-
}
83-
8481
sourceLink {
8582
localDirectory.set(rootDir)
86-
remoteUrl.set(java.net.URL("https://github.com/appmattus/multiplatform-utils/blob/main"))
83+
remoteUrl("https://github.com/appmattus/multiplatform-utils/blob/main")
8784
remoteLineSuffix.set("#L")
8885
}
8986
}
9087
}
88+
89+
pluginsConfiguration.html {
90+
footerMessage.set(
91+
provider {
92+
"Copyright © 2021-${ZonedDateTime.now().year} Appmattus Limited"
93+
}
94+
)
95+
}
9196
}
9297
}
9398
}

0 commit comments

Comments
 (0)