diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index f4b64b3560..eaa03f2f15 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -59,5 +59,9 @@ dependencies { exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") } implementation("ru.vyarus:gradle-animalsniffer-plugin:1.5.3") // Android API check - implementation("org.jetbrains.kotlinx:kover:${version("kover")}") + implementation("org.jetbrains.kotlinx:kover:${version("kover")}") { + exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8") + exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7") + exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") + } } diff --git a/buildSrc/src/main/kotlin/UnpackAar.kt b/buildSrc/src/main/kotlin/UnpackAar.kt index b3152d7ab0..afe2627a3d 100644 --- a/buildSrc/src/main/kotlin/UnpackAar.kt +++ b/buildSrc/src/main/kotlin/UnpackAar.kt @@ -2,18 +2,49 @@ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +import org.gradle.api.* import org.gradle.api.artifacts.transform.InputArtifact import org.gradle.api.artifacts.transform.TransformAction import org.gradle.api.artifacts.transform.TransformOutputs import org.gradle.api.artifacts.transform.TransformParameters +import org.gradle.api.attributes.* import org.gradle.api.file.FileSystemLocation import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.* import java.io.File import java.nio.file.Files import java.util.zip.ZipEntry import java.util.zip.ZipFile -// TODO move back to kotlinx-coroutines-play-services when it's migrated to the kts +// Attributes used by aar dependencies +val artifactType = Attribute.of("artifactType", String::class.java) +val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) + +fun Project.configureAar() = configurations.configureEach { + afterEvaluate { + if (isCanBeResolved && !isCanBeConsumed) { + attributes.attribute(unpackedAar, true) // request all AARs to be unpacked + } + } +} + +fun DependencyHandlerScope.configureAarUnpacking() { + attributesSchema { + attribute(unpackedAar) + } + + artifactTypes { + create("aar") { + attributes.attribute(unpackedAar, false) + } + } + + registerTransform(UnpackAar::class.java) { + from.attribute(unpackedAar, false).attribute(artifactType, "aar") + to.attribute(unpackedAar, true).attribute(artifactType, "jar") + } +} + @Suppress("UnstableApiUsage") abstract class UnpackAar : TransformAction { @get:InputArtifact diff --git a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts index 125ddb19ea..052e2bb684 100644 --- a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts @@ -13,10 +13,8 @@ val expectedCoverage = mutableMapOf( "kotlinx-coroutines-swing" to 70, // awaitFrame is not tested "kotlinx-coroutines-javafx" to 39, // JavaFx is not tested on TC because its graphic subsystem cannot be initialized in headless mode - // Re-evaluate this along with Kover update where deprecated with error+ functions are not considered as uncovered: IDEA-287459 - "kotlinx-coroutines-reactor" to 65, - "kotlinx-coroutines-rx2" to 78 -) + // Reactor has lower coverage in general due to various fatal error handling features + "kotlinx-coroutines-reactor" to 75) extensions.configure { disabledProjects = notCovered @@ -28,6 +26,8 @@ extensions.configure { * ./gradlew :p:koverReport -Pkover.enabled=true -- generates report */ isDisabled = !(properties["kover.enabled"]?.toString()?.toBoolean() ?: false) + // TODO remove when updating Kover to version 0.5.x + intellijEngineVersion.set("1.0.657") } subprojects { diff --git a/gradle.properties b/gradle.properties index 7794ba71aa..e06f587df7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,14 +23,14 @@ rxjava3_version=3.0.2 javafx_version=11.0.2 javafx_plugin_version=0.0.8 binary_compatibility_validator_version=0.8.0 -kover_version=0.5.0-RC2 +kover_version=0.5.0 blockhound_version=1.0.2.RELEASE jna_version=5.9.0 # Android versions android_version=4.1.1.4 androidx_annotation_version=1.1.0 -robolectric_version=4.0.2 +robolectric_version=4.4 baksmali_version=2.2.7 # JS diff --git a/integration/kotlinx-coroutines-play-services/build.gradle.kts b/integration/kotlinx-coroutines-play-services/build.gradle.kts index 59f3b0bd5a..9f8a128703 100644 --- a/integration/kotlinx-coroutines-play-services/build.gradle.kts +++ b/integration/kotlinx-coroutines-play-services/build.gradle.kts @@ -4,36 +4,17 @@ val tasksVersion = "16.0.1" -val artifactType = Attribute.of("artifactType", String::class.java) -val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) - -configurations.configureEach { - afterEvaluate { - if (isCanBeResolved) { - attributes.attribute(unpackedAar, true) // request all AARs to be unpacked - } - } -} +project.configureAar() dependencies { - attributesSchema { - attribute(unpackedAar) - } - - artifactTypes { - create("aar") { - attributes.attribute(unpackedAar, false) - } - } - - registerTransform(UnpackAar::class.java) { - from.attribute(unpackedAar, false).attribute(artifactType, "aar") - to.attribute(unpackedAar, true).attribute(artifactType, "jar") - } - + configureAarUnpacking() api("com.google.android.gms:play-services-tasks:$tasksVersion") { exclude(group="com.android.support") } + + // Required by robolectric + testImplementation("androidx.test:core:1.2.0") + testImplementation("androidx.test:monitor:1.2.0") } externalDocumentationLink( diff --git a/reactive/kotlinx-coroutines-reactor/build.gradle.kts b/reactive/kotlinx-coroutines-reactor/build.gradle.kts index 5abf3862dc..1a36ccec28 100644 --- a/reactive/kotlinx-coroutines-reactor/build.gradle.kts +++ b/reactive/kotlinx-coroutines-reactor/build.gradle.kts @@ -29,7 +29,8 @@ externalDocumentationLink( ) val commonKoverExcludes = listOf( - "kotlinx.coroutines.reactor.FlowKt" // Deprecated + "kotlinx.coroutines.reactor.FlowKt", // Deprecated + "kotlinx.coroutines.reactor.ConvertKt\$asFlux$1" // Deprecated ) tasks.koverHtmlReport { diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts b/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts index 2fd0b81479..625ce728b1 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts +++ b/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts @@ -2,10 +2,17 @@ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +project.configureAar() + dependencies { - kotlinCompilerPluginClasspathMain(project(":kotlinx-coroutines-core")) + configureAarUnpacking() + testImplementation("com.google.android:android:${version("android")}") testImplementation("org.robolectric:robolectric:${version("robolectric")}") + // Required by robolectric + testImplementation("androidx.test:core:1.2.0") + testImplementation("androidx.test:monitor:1.2.0") + testImplementation(project(":kotlinx-coroutines-test")) testImplementation(project(":kotlinx-coroutines-android")) } diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt index bcc12d5441..676ee4310d 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt +++ b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt @@ -26,6 +26,7 @@ class InitMainDispatcherBeforeRobolectricTestRunner(testClass: Class<*>) : Robol @Config(manifest = Config.NONE, sdk = [28]) @RunWith(InitMainDispatcherBeforeRobolectricTestRunner::class) +@LooperMode(LooperMode.Mode.LEGACY) class CustomizedRobolectricTest : TestBase() { @Test fun testComponent() { @@ -52,4 +53,4 @@ class CustomizedRobolectricTest : TestBase() { mainLooper.unPause() assertTrue(component.launchCompleted) } -} \ No newline at end of file +} diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt index eab6fc17fb..99744f897f 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt +++ b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt @@ -15,6 +15,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) open class FirstRobolectricTest { @Test fun testComponent() { diff --git a/ui/kotlinx-coroutines-android/build.gradle.kts b/ui/kotlinx-coroutines-android/build.gradle.kts index 145ad9f6b4..7618c529f7 100644 --- a/ui/kotlinx-coroutines-android/build.gradle.kts +++ b/ui/kotlinx-coroutines-android/build.gradle.kts @@ -10,16 +10,24 @@ configurations { repositories { mavenCentral() - jcenter() // https://youtrack.jetbrains.com/issue/IDEA-261387 } + +project.configureAar() + dependencies { + configureAarUnpacking() + compileOnly("com.google.android:android:${version("android")}") compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}") testImplementation("com.google.android:android:${version("android")}") testImplementation("org.robolectric:robolectric:${version("robolectric")}") - testImplementation("org.smali:baksmali:${version("baksmali")}") + // Required by robolectric + testImplementation("androidx.test:core:1.2.0") + testImplementation("androidx.test:monitor:1.2.0") + + testImplementation("org.smali:baksmali:${version("baksmali")}") "r8"("com.android.tools.build:builder:7.1.0-alpha01") } diff --git a/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt b/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt index 4aa44eceaf..1220797009 100644 --- a/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt +++ b/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt @@ -13,6 +13,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [27]) +@LooperMode(LooperMode.Mode.LEGACY) class AndroidExceptionPreHandlerTest : TestBase() { @Test fun testUnhandledException() = runTest { diff --git a/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt b/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt index a1f0a03d4a..a5b5ec95ee 100644 --- a/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt +++ b/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt @@ -13,6 +13,7 @@ import org.robolectric.annotation.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) class DisabledHandlerTest : TestBase() { private var delegateToSuper = false diff --git a/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt b/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt index 7b03e771f9..c2091f339f 100644 --- a/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt +++ b/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt @@ -18,6 +18,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) class HandlerDispatcherAsyncTest : TestBase() { /** diff --git a/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt b/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt index 24758444b0..fe97ae8d27 100644 --- a/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt +++ b/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt @@ -16,6 +16,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) class HandlerDispatcherTest : TestBase() { @Test fun testImmediateDispatcherYield() = runBlocking(Dispatchers.Main) { @@ -121,7 +122,6 @@ class HandlerDispatcherTest : TestBase() { } private fun CoroutineScope.doTestAwaitWithDetectedChoreographer() { - ShadowChoreographer.reset() ShadowChoreographer.setPostFrameCallbackDelay(100) val mainLooper = Shadows.shadowOf(Looper.getMainLooper()) launch(Dispatchers.Main, start = CoroutineStart.UNDISPATCHED) {