Skip to content

Commit

Permalink
Update to Kotlin 1.5.10, bump other dependencies, clear compiler warn…
Browse files Browse the repository at this point in the history
…ings (#198)
  • Loading branch information
russhwolf committed May 28, 2021
1 parent 4920da9 commit 7f79e90
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}
}
compileOptions {
coreLibraryDesugaringEnabled = true
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Expand All @@ -40,6 +40,7 @@ android {

kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}

Expand All @@ -64,6 +65,5 @@ dependencies {
implementation(Deps.AndroidX.lifecycle_viewmodel)
implementation(Deps.AndroidX.lifecycle_viewmodel_extensions)
implementation(Deps.AndroidX.lifecycle_livedata)
implementation(Deps.AndroidX.lifecycle_extension)
testImplementation(Deps.junit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MainViewHolder(binding: ItemBreedBinding, breedClickListener: (Int) -> Uni
private val favoriteButton = binding.favoriteButton

init {
favoriteButton.setOnClickListener { breedClickListener(adapterPosition) }
favoriteButton.setOnClickListener { breedClickListener(bindingAdapterPosition) }
}

fun bindTo(breed: Breed) {
Expand Down
33 changes: 16 additions & 17 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ object Versions {
val target_sdk = 30
val compile_sdk = 30

val kotlin = "1.4.32"
val android_gradle_plugin = "4.0.2"
val kotlin = "1.5.10"
val android_gradle_plugin = "4.1.1"

val buildToolsVersion = "30.0.3"
val coroutines = "1.4.3-native-mt"
val kermit = "0.1.8"
val koin = "3.0.1"
val ktlint_gradle_plugin = "9.4.1"
val ktor = "1.5.3"
val coroutines = "1.5.0-native-mt"
val kermit = "0.1.9"
val koin = "3.0.2"
val ktlint_gradle_plugin = "10.0.0"
val ktor = "1.6.0"
val junit = "4.13.2"
val material = "1.3.0"
val desugarJdkLibs = "1.1.5"
val multiplatformSettings = "0.7.5"
val multiplatformSettings = "0.7.7"
val robolectric = "4.5.1"
val sqlDelight = "1.5.0"
val stately = "1.1.6"
val serialization = "1.1.0"
val kotlinxDateTime = "0.1.1"
val turbine = "0.4.1"
val stately = "1.1.7"
val serialization = "1.2.1"
val kotlinxDateTime = "0.2.1"
val turbine = "0.5.1"

object AndroidX {
val appcompat = "1.2.0"
val appcompat = "1.3.0"
val constraintlayout = "2.0.4"
val core = "1.3.2"
val lifecycle = "2.2.0"
val recyclerview = "1.1.0"
val core = "1.5.0"
val lifecycle = "2.3.1"
val recyclerview = "1.2.0"
val swipeRefresh = "1.1.0"
val test = "1.3.0"
val test_ext = "1.1.2"
Expand Down Expand Up @@ -62,7 +62,6 @@ object Deps {
val lifecycle_viewmodel = "androidx.lifecycle:lifecycle-viewmodel:${Versions.AndroidX.lifecycle}"
val lifecycle_viewmodel_extensions = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.AndroidX.lifecycle}"
val lifecycle_livedata = "androidx.lifecycle:lifecycle-livedata:${Versions.AndroidX.lifecycle}"
val lifecycle_extension = "androidx.lifecycle:lifecycle-extensions:${Versions.AndroidX.lifecycle}"
}

object AndroidXTest {
Expand Down
12 changes: 7 additions & 5 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ kotlin {
implementation(Deps.Ktor.commonCore)
implementation(Deps.Ktor.commonJson)
implementation(Deps.Ktor.commonLogging)
implementation(Deps.Coroutines.common) {
version {
strictly(Versions.coroutines)
}
}
implementation(Deps.Coroutines.common)
implementation(Deps.stately)
implementation(Deps.multiplatformSettings)
implementation(Deps.koinCore)
Expand Down Expand Up @@ -101,6 +97,12 @@ kotlin {
sourceSets["iosMain"].dependencies {
implementation(Deps.SqlDelight.driverIos)
implementation(Deps.Ktor.ios)

implementation(Deps.Coroutines.common) {
version {
strictly(Versions.coroutines)
}
}
}

cocoapods {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package co.touchlab.kampkit

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExecutorCoroutineDispatcher
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import java.util.concurrent.Executors

/**
* Use this rule to update the Main dispatcher ahead of tests. By delegating the main dispatcher to a new thread.
* we can block the current thread and still dispatch main coroutines
*/
class CoroutineTestRule(
private val testDispatcher: ExecutorCoroutineDispatcher = newSingleThreadContext("UI thread")
private val testDispatcher: ExecutorCoroutineDispatcher = Executors.newSingleThreadExecutor()
.asCoroutineDispatcher()
) : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.time.hours
import kotlin.time.seconds
import kotlin.time.Duration

class BreedModelTest : BaseTest() {

Expand Down Expand Up @@ -129,7 +128,7 @@ class BreedModelTest : BaseTest() {
val successResult = ktorApi.successResult()
ktorApi.prepareResult(successResult)
flowOf(model.refreshBreedsIfStale(), model.getBreedsFromCache()).flattenMerge()
.test(timeout = 30.seconds) {
.test(timeout = Duration.seconds(30)) {
assertEquals(DataState.Loading, expectItem())
val oldBreeds = expectItem()
assertTrue(oldBreeds is DataState.Success)
Expand All @@ -140,12 +139,12 @@ class BreedModelTest : BaseTest() {
}

// Advance time by more than an hour to make cached data stale
clock.currentInstant += 2.hours
clock.currentInstant += Duration.hours(2)
val resultWithExtraBreed = successResult.copy(message = successResult.message + ("extra" to emptyList()))

ktorApi.prepareResult(resultWithExtraBreed)
flowOf(model.refreshBreedsIfStale(), model.getBreedsFromCache()).flattenMerge()
.test(timeout = 30.seconds) {
.test(timeout = Duration.seconds(30)) {
assertEquals(DataState.Loading, expectItem())
val updated = expectItem()
assertTrue(updated is DataState.Success)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.touchlab.kampkit

import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
Expand All @@ -14,6 +15,7 @@ class ConcurrencyTest : BaseTest() {
* This doesn't test any KampKit code, but is a sanity check that our tests can handle main thread
* coroutines without hanging
*/
@OptIn(DelicateCoroutinesApi::class)
@Test
fun testMain() {
runTest {
Expand Down
2 changes: 2 additions & 0 deletions shared/src/iosTest/kotlin/co/touchlab/kampkit/BaseTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.touchlab.kampkit

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand All @@ -9,6 +10,7 @@ import platform.CoreFoundation.CFRunLoopRun
import platform.CoreFoundation.CFRunLoopStop

actual abstract class BaseTest {
@OptIn(DelicateCoroutinesApi::class)
actual fun <T> runTest(block: suspend CoroutineScope.() -> T) {
var error: Throwable? = null
GlobalScope.launch(Dispatchers.Main) {
Expand Down

0 comments on commit 7f79e90

Please sign in to comment.