Add a gradle property for allWarningsAsErrors.
Additionally, fix all warnings in host tests as these did not have
warnings as errors enabled before.
This also allows developers to enable it on a single task as
./gradlew core:core:assembleDebug --Pandroidx.allWarningsAsErrors
Test: Locally tested the flag on a task
Change-Id: I70b3542e09ca4ba1a569e85f43c49c0d7d061003
diff --git a/buildSrc/src/main/kotlin/androidx/build/AndroidXGradleProperties.kt b/buildSrc/src/main/kotlin/androidx/build/AndroidXGradleProperties.kt
index 9534150..566bbd8 100644
--- a/buildSrc/src/main/kotlin/androidx/build/AndroidXGradleProperties.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/AndroidXGradleProperties.kt
@@ -17,8 +17,13 @@
package androidx.build
/**
- * Setting this property to true makes Test tasks succeed even if there
+ * Setting this property makes Test tasks succeed even if there
* are some failing tests. Useful when running tests in CI where build
* passes test results as XML to test reporter.
*/
const val TEST_FAILURES_DO_NOT_FAIL_TEST_TASK = "androidx.ignoreTestFailures"
+
+/**
+ * Setting this property turns javac and kotlinc warnings into errors that fail the build.
+ */
+const val ALL_WARNINGS_AS_ERRORS = "androidx.allWarningsAsErrors"
\ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt
index e201f16..df4a38b 100644
--- a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt
@@ -362,14 +362,6 @@
}
}
}
- // If we are running buildOnServer, run all actions in buildOnServerDependentActions after
- // the task graph has been resolved, before we are in the execution phase.
- project.gradle.taskGraph.whenReady { taskExecutionGraph ->
- // hasTask requires the task path, so we are looking for the root :buildOnServer task
- if (taskExecutionGraph.hasTask(":$BUILD_ON_SERVER_TASK")) {
- buildOnServerDependentActions.forEach { it() }
- }
- }
registerStudioTask()
@@ -773,41 +765,16 @@
return File(buildDir, "intermediates/public_res/release/public.txt")
}
-/**
- * Delays execution of the given [action] until the task graph is ready, and we know whether
- * we are running buildOnServer
- */
-private fun Project.runIfPartOfBuildOnServer(action: () -> Unit) {
- buildOnServerDependentActions.add(action)
-}
-
-/**
- * A list of configuration actions that will only be applied if buildOnServer is part of
- * the task graph, essentially when we are running ./gradlew buildOnServer
- */
-private val Project.buildOnServerDependentActions: MutableList<() -> Unit> get() {
- val extraProperties = rootProject.extensions.extraProperties
- if (!extraProperties.has(BUILD_ON_SERVER_DEPENDENT_ACTIONS)) {
- extraProperties.set(BUILD_ON_SERVER_DEPENDENT_ACTIONS, mutableListOf<() -> Unit>())
- }
- @Suppress("UNCHECKED_CAST")
- return extraProperties.get(BUILD_ON_SERVER_DEPENDENT_ACTIONS) as MutableList<() -> Unit>
-}
-
private fun Project.configureCompilationWarnings(task: JavaCompile) {
- if (!project.rootProject.hasProperty(USE_MAX_DEP_VERSIONS)) {
- runIfPartOfBuildOnServer {
+ if (hasProperty(ALL_WARNINGS_AS_ERRORS)) {
task.options.compilerArgs.add("-Werror")
task.options.compilerArgs.add("-Xlint:unchecked")
- }
}
}
private fun Project.configureCompilationWarnings(task: KotlinCompile) {
- if (!project.rootProject.hasProperty(USE_MAX_DEP_VERSIONS)) {
- runIfPartOfBuildOnServer {
- task.kotlinOptions.allWarningsAsErrors = true
- }
+ if (hasProperty(ALL_WARNINGS_AS_ERRORS)) {
+ task.kotlinOptions.allWarningsAsErrors = true
}
}
diff --git a/busytown/androidx-studio-integration.sh b/busytown/androidx-studio-integration.sh
index b1f4cd0..745d941 100755
--- a/busytown/androidx-studio-integration.sh
+++ b/busytown/androidx-studio-integration.sh
@@ -22,5 +22,5 @@
export JAVA_TOOLS_JAR="$PWD/prebuilts/jdk/jdk11/linux-x86/lib/tools.jar"
export LINT_PRINT_STACKTRACE=true
-tools/gradlew -p frameworks/support --no-daemon bOS --stacktrace
-DIST_SUBDIR="/ui" tools/gradlew -p frameworks/support/ui --no-daemon bOS --stacktrace
+tools/gradlew -p frameworks/support --no-daemon bOS --stacktrace -Pandroidx.allWarningsAsErrors
+DIST_SUBDIR="/ui" tools/gradlew -p frameworks/support/ui --no-daemon bOS --stacktrace -Pandroidx.allWarningsAsErrors
diff --git a/busytown/androidx.sh b/busytown/androidx.sh
index b958850..0fe2edcb 100755
--- a/busytown/androidx.sh
+++ b/busytown/androidx.sh
@@ -5,7 +5,9 @@
# Run Gradle
impl/build.sh --no-daemon listTaskOutputs "$@"
-impl/build.sh --no-daemon buildOnServer -PverifyUpToDate --profile "$@"
+impl/build.sh --no-daemon buildOnServer \
+ -PverifyUpToDate \
+ -Pandroidx.allWarningsAsErrors --profile "$@"
# Merge some output files
python3 impl/merge_outputs.py "mergeBuildInfo" "mergeLibraryMetrics"
diff --git a/busytown/androidx_host_tests.sh b/busytown/androidx_host_tests.sh
index bc6ef29..3c0f0cf 100755
--- a/busytown/androidx_host_tests.sh
+++ b/busytown/androidx_host_tests.sh
@@ -3,7 +3,10 @@
cd "$(dirname $0)"
-impl/build.sh --no-daemon test jacocoTestReport zipEcFiles --info --offline -Pandroidx.enableAffectedModuleDetection -Pandroidx.ignoreTestFailures "$@"
+impl/build.sh --no-daemon test jacocoTestReport zipEcFiles --info --offline \
+ -Pandroidx.enableAffectedModuleDetection \
+ -Pandroidx.ignoreTestFailures \
+ -Pandroidx.allWarningsAsErrors "$@"
# TODO: un-comment this when AMD is fixed (b/147824472)
#python3 ./merge_outputs.py mergeExecutionData
diff --git a/busytown/androidx_snapshot.sh b/busytown/androidx_snapshot.sh
index f02df74..f0d9f40 100755
--- a/busytown/androidx_snapshot.sh
+++ b/busytown/androidx_snapshot.sh
@@ -3,4 +3,4 @@
cd "$(dirname $0)"
-SNAPSHOT=true impl/build.sh --no-daemon createArchive --offline "$@"
+SNAPSHOT=true impl/build.sh --no-daemon createArchive -Pandroidx.allWarningsAsErrors --offline "$@"
diff --git a/busytown/androidx_test_changed_apks.sh b/busytown/androidx_test_changed_apks.sh
index a218fc3..7c03b90 100755
--- a/busytown/androidx_test_changed_apks.sh
+++ b/busytown/androidx_test_changed_apks.sh
@@ -3,4 +3,7 @@
cd "$(dirname $0)"
-impl/build.sh --no-daemon buildTestApks -Pandroidx.enableAffectedModuleDetection -Pandroidx.changedProjects --offline "$@"
+impl/build.sh --no-daemon buildTestApks \
+ -Pandroidx.enableAffectedModuleDetection \
+ -Pandroidx.changedProjects \
+ -Pandroidx.allWarningsAsErrors --offline "$@"
diff --git a/busytown/androidx_test_dependent_apks.sh b/busytown/androidx_test_dependent_apks.sh
index 298c50c..407e335 100755
--- a/busytown/androidx_test_dependent_apks.sh
+++ b/busytown/androidx_test_dependent_apks.sh
@@ -3,4 +3,7 @@
cd "$(dirname $0)"
-impl/build.sh --no-daemon buildTestApks -Pandroidx.enableAffectedModuleDetection -Pandroidx.dependentProjects --offline "$@"
+impl/build.sh --no-daemon buildTestApks \
+ -Pandroidx.enableAffectedModuleDetection \
+ -Pandroidx.dependentProjects \
+ -Pandroidx.allWarningsAsErrors --offline "$@"
diff --git a/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/AbstractLoweringTests.kt b/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/AbstractLoweringTests.kt
index eabfe47..7b8dd9f 100644
--- a/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/AbstractLoweringTests.kt
+++ b/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/AbstractLoweringTests.kt
@@ -105,7 +105,7 @@
return compose {
val values = valuesFactory()
- val arguments = values.map { it.value as Any }.toTypedArray()
+ val arguments = values.map { it.value }.toTypedArray()
testMethod.invoke(instanceOfClass, *arguments, it)
}
}
diff --git a/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/KtxCrossModuleTests.kt b/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/KtxCrossModuleTests.kt
index 99f35e2..ec2c295 100644
--- a/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/KtxCrossModuleTests.kt
+++ b/compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/KtxCrossModuleTests.kt
@@ -42,7 +42,7 @@
@Test
fun testCrossinlineEmittable(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/A.kt" to """
package x
@@ -76,7 +76,7 @@
@Test
fun testConstCrossModule(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/A.kt" to """
package x
@@ -105,7 +105,7 @@
@Test
fun testNonCrossinlineComposable(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/A.kt" to """
package x
@@ -138,7 +138,7 @@
@Test
fun testNonCrossinlineComposableNoGenerics(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/A.kt" to """
package x
@@ -174,7 +174,7 @@
@Test
fun testRemappedTypes(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/A.kt" to """
package x
@@ -210,7 +210,7 @@
@Test
fun testInlineIssue(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/C.kt" to """
fun ghi() {
@@ -239,7 +239,7 @@
@Test
fun testInlineComposableProperty(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/A.kt" to """
package x
@@ -272,7 +272,7 @@
@Test
fun testNestedInlineIssue(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/C.kt" to """
fun ghi() {
@@ -309,7 +309,7 @@
@Test
fun testComposerIntrinsicInline(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/C.kt" to """
import androidx.compose.Composable
@@ -350,7 +350,7 @@
@Test
fun testComposableOrderIssue(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"C.kt" to """
import androidx.compose.*
@@ -389,7 +389,7 @@
@Test
fun testSimpleXModuleCall(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"a/A.kt" to """
package a
@@ -420,7 +420,7 @@
@Test
fun testJvmFieldIssue(): Unit = ensureSetup {
compile(
- "TestG", mapOf(
+ mapOf(
"library module" to mapOf(
"x/C.kt" to """
fun Test2() {
@@ -449,7 +449,7 @@
@Test
fun testInstanceXModuleCall(): Unit = ensureSetup {
compile(
- "TestH", mapOf(
+ mapOf(
"library module" to mapOf(
"a/Foo.kt" to """
package a
@@ -480,7 +480,7 @@
@Test
fun testXModuleProperty(): Unit = ensureSetup {
compile(
- "TestI", mapOf(
+ mapOf(
"library module" to mapOf(
"a/Foo.kt" to """
package a
@@ -508,7 +508,7 @@
@Test
fun testXModuleInterface(): Unit = ensureSetup {
compile(
- "TestJ", mapOf(
+ mapOf(
"library module" to mapOf(
"a/Foo.kt" to """
package a
@@ -542,7 +542,7 @@
@Test
fun testXModuleCtorComposableParam(): Unit = ensureSetup {
compile(
- "TestJ", mapOf(
+ mapOf(
"library module" to mapOf(
"a/Foo.kt" to """
package a
@@ -772,7 +772,6 @@
}
fun compile(
- mainClassName: String,
modules: Map<String, Map<String, String>>,
dumpClasses: Boolean = false,
validate: ((String) -> Unit)? = null
@@ -816,7 +815,7 @@
modules: Map<String, Map<String, String>>,
dumpClasses: Boolean = false
): RobolectricComposeTester {
- val allClasses = compile(mainClassName, modules, dumpClasses)
+ val allClasses = compile(modules, dumpClasses)
val loader = URLClassLoader(emptyArray(), this.javaClass.classLoader)
val instanceClass = run {
var instanceClass: Class<*>? = null
diff --git a/concurrent/futures-ktx/build.gradle b/concurrent/futures-ktx/build.gradle
index 9635af1..29766ca 100644
--- a/concurrent/futures-ktx/build.gradle
+++ b/concurrent/futures-ktx/build.gradle
@@ -19,6 +19,7 @@
import androidx.build.LibraryGroups
import androidx.build.LibraryVersions
import androidx.build.Publish
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import static androidx.build.dependencies.DependenciesKt.*
@@ -47,3 +48,10 @@
description = "Kotlin Extensions for Androidx implementation of Guava's ListenableFuture"
url = AndroidXExtension.ARCHITECTURE_URL
}
+
+// Allow usage of Kotlin's @OptIn.
+tasks.withType(KotlinCompile).configureEach {
+ kotlinOptions {
+ freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
+ }
+}
diff --git a/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt b/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt
index 11147a0..562b8a0 100644
--- a/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt
+++ b/concurrent/futures-ktx/src/test/java/androidx/concurrent/futures/ListenableFutureTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.concurrent.futures
import kotlinx.coroutines.CancellationException
diff --git a/fragment/fragment/src/test/java/androidx/fragment/app/FragmentPagerActivity.kt b/fragment/fragment/src/test/java/androidx/fragment/app/FragmentPagerActivity.kt
index 958c7e8..4d3c9cf 100644
--- a/fragment/fragment/src/test/java/androidx/fragment/app/FragmentPagerActivity.kt
+++ b/fragment/fragment/src/test/java/androidx/fragment/app/FragmentPagerActivity.kt
@@ -1,3 +1,5 @@
+@file:Suppress("DEPRECATION")
+
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
diff --git a/lifecycle/integration-tests/kotlintestapp/src/test/java/androidx/lifecycle/LifecycleCoroutineScopeTest.kt b/lifecycle/integration-tests/kotlintestapp/src/test/java/androidx/lifecycle/LifecycleCoroutineScopeTest.kt
index 8eaae40..a2af184 100644
--- a/lifecycle/integration-tests/kotlintestapp/src/test/java/androidx/lifecycle/LifecycleCoroutineScopeTest.kt
+++ b/lifecycle/integration-tests/kotlintestapp/src/test/java/androidx/lifecycle/LifecycleCoroutineScopeTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.lifecycle
import kotlinx.coroutines.Dispatchers
diff --git a/lifecycle/lifecycle-livedata-core-ktx/build.gradle b/lifecycle/lifecycle-livedata-core-ktx/build.gradle
index 61f7450..6eec55d 100644
--- a/lifecycle/lifecycle-livedata-core-ktx/build.gradle
+++ b/lifecycle/lifecycle-livedata-core-ktx/build.gradle
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
import static androidx.build.dependencies.DependenciesKt.*
import androidx.build.LibraryGroups
import androidx.build.LibraryVersions
@@ -52,3 +55,10 @@
inceptionYear = "2018"
description = "Kotlin extensions for 'livedata-core' artifact"
}
+
+// Allow usage of Kotlin's @OptIn.
+tasks.withType(KotlinCompile).configureEach {
+ kotlinOptions {
+ freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
+ }
+}
diff --git a/lifecycle/lifecycle-livedata-core-ktx/src/test/java/androidx/lifecycle/LiveDataTest.kt b/lifecycle/lifecycle-livedata-core-ktx/src/test/java/androidx/lifecycle/LiveDataTest.kt
index c264829..ccc1bee 100644
--- a/lifecycle/lifecycle-livedata-core-ktx/src/test/java/androidx/lifecycle/LiveDataTest.kt
+++ b/lifecycle/lifecycle-livedata-core-ktx/src/test/java/androidx/lifecycle/LiveDataTest.kt
@@ -30,6 +30,7 @@
@Test
fun observe() {
+ @OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
val lifecycleOwner = TestLifecycleOwner(coroutineDispatcher = TestCoroutineDispatcher())
val liveData = MutableLiveData<String>()
diff --git a/lifecycle/lifecycle-livedata-core-truth/src/test/java/androidx/lifecycle/truth/LiveDataSubjectTest.kt b/lifecycle/lifecycle-livedata-core-truth/src/test/java/androidx/lifecycle/truth/LiveDataSubjectTest.kt
index a3003f1..854423b 100644
--- a/lifecycle/lifecycle-livedata-core-truth/src/test/java/androidx/lifecycle/truth/LiveDataSubjectTest.kt
+++ b/lifecycle/lifecycle-livedata-core-truth/src/test/java/androidx/lifecycle/truth/LiveDataSubjectTest.kt
@@ -31,6 +31,7 @@
@Test
fun testHasActiveObservers() {
+ @Suppress("UNCHECKED_CAST")
val observer = mock(Observer::class.java) as Observer<Any>
val liveData = MutableLiveData<Any>()
liveData.observeForever(observer)
diff --git a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
index e23b763..1d3e128 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.lifecycle
import com.google.common.truth.Truth.assertThat
diff --git a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt
index d46b44fb..9a6ee18 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/FlowAsLiveDataTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.lifecycle
import com.google.common.truth.Truth.assertThat
diff --git a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/LiveDataAsFlowTest.kt b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/LiveDataAsFlowTest.kt
index 6e2f7c6..51ac28c 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/LiveDataAsFlowTest.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/LiveDataAsFlowTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.lifecycle
import com.google.common.truth.Truth.assertThat
diff --git a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/ScopesRule.kt b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/ScopesRule.kt
index c611d1d..529d3bf 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/ScopesRule.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/ScopesRule.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.lifecycle
import androidx.arch.core.executor.ArchTaskExecutor
diff --git a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/TransformationsTest.kt b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/TransformationsTest.kt
index b3c6ed6..a90d49f 100644
--- a/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/TransformationsTest.kt
+++ b/lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/TransformationsTest.kt
@@ -28,6 +28,7 @@
@get:Rule
val mInstantTaskExecutorRule = InstantTaskExecutorRule()
+ @OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
private val lifecycleOwner = TestLifecycleOwner(
coroutineDispatcher = TestCoroutineDispatcher())
diff --git a/lifecycle/lifecycle-reactivestreams-ktx/build.gradle b/lifecycle/lifecycle-reactivestreams-ktx/build.gradle
index 75015d5..4e850f2 100644
--- a/lifecycle/lifecycle-reactivestreams-ktx/build.gradle
+++ b/lifecycle/lifecycle-reactivestreams-ktx/build.gradle
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
import static androidx.build.dependencies.DependenciesKt.*
import androidx.build.LibraryGroups
import androidx.build.LibraryVersions
@@ -47,3 +50,10 @@
description = "Kotlin extensions for Lifecycle ReactiveStreams"
url = AndroidXExtension.ARCHITECTURE_URL
}
+
+// Allow usage of Kotlin's @OptIn.
+tasks.withType(KotlinCompile).configureEach {
+ kotlinOptions {
+ freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
+ }
+}
\ No newline at end of file
diff --git a/lifecycle/lifecycle-reactivestreams-ktx/src/test/java/androidx/lifecycle/LiveDataReactiveStreamsTest.kt b/lifecycle/lifecycle-reactivestreams-ktx/src/test/java/androidx/lifecycle/LiveDataReactiveStreamsTest.kt
index d6233a9..9a5f938 100644
--- a/lifecycle/lifecycle-reactivestreams-ktx/src/test/java/androidx/lifecycle/LiveDataReactiveStreamsTest.kt
+++ b/lifecycle/lifecycle-reactivestreams-ktx/src/test/java/androidx/lifecycle/LiveDataReactiveStreamsTest.kt
@@ -32,6 +32,7 @@
private lateinit var lifecycleOwner: LifecycleOwner
@Before fun init() {
+ @OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
lifecycleOwner = TestLifecycleOwner(coroutineDispatcher = TestCoroutineDispatcher())
}
diff --git a/lifecycle/lifecycle-runtime-testing/build.gradle b/lifecycle/lifecycle-runtime-testing/build.gradle
index 47224d8..3cc4035 100644
--- a/lifecycle/lifecycle-runtime-testing/build.gradle
+++ b/lifecycle/lifecycle-runtime-testing/build.gradle
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
import static androidx.build.dependencies.DependenciesKt.*
import androidx.build.LibraryGroups
import androidx.build.LibraryVersions
@@ -56,3 +59,10 @@
inceptionYear = "2019"
description = "Testing utilities for 'lifecycle' artifact"
}
+
+// Allow usage of Kotlin's @OptIn.
+tasks.withType(KotlinCompile).configureEach {
+ kotlinOptions {
+ freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
+ }
+}
diff --git a/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt b/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt
index 93a4c78..4fba3da 100644
--- a/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt
+++ b/lifecycle/lifecycle-runtime-testing/src/test/java/androidx/lifecycle/testing/LifecycleRegistryTest.kt
@@ -26,8 +26,11 @@
@RunWith(JUnit4::class)
class LifecycleRegistryTest {
- private val lifecycleOwner = TestLifecycleOwner(Lifecycle.State.INITIALIZED,
- TestCoroutineDispatcher())
+ @OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+ private val lifecycleOwner = TestLifecycleOwner(
+ Lifecycle.State.INITIALIZED,
+ TestCoroutineDispatcher()
+ )
@Test
fun getCurrentState() {
diff --git a/paging/common/src/test/kotlin/androidx/paging/CachingTest.kt b/paging/common/src/test/kotlin/androidx/paging/CachingTest.kt
index 113bcfa..07de3aa 100644
--- a/paging/common/src/test/kotlin/androidx/paging/CachingTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/CachingTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.paging
import androidx.paging.ActiveFlowTracker.FlowType
diff --git a/paging/common/src/test/kotlin/androidx/paging/ContiguousPagedListTest.kt b/paging/common/src/test/kotlin/androidx/paging/ContiguousPagedListTest.kt
index a8139d8..a53bc0b2 100644
--- a/paging/common/src/test/kotlin/androidx/paging/ContiguousPagedListTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/ContiguousPagedListTest.kt
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+@file:Suppress("DEPRECATION")
+
package androidx.paging
import androidx.paging.ItemKeyedDataSourceTest.ItemDataSource
diff --git a/paging/common/src/test/kotlin/androidx/paging/HeaderFooterTest.kt b/paging/common/src/test/kotlin/androidx/paging/HeaderFooterTest.kt
index 862dfd2..fb3c12e 100644
--- a/paging/common/src/test/kotlin/androidx/paging/HeaderFooterTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/HeaderFooterTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.paging
import androidx.paging.LoadState.Done
diff --git a/paging/common/src/test/kotlin/androidx/paging/LegacyPagerTest.kt b/paging/common/src/test/kotlin/androidx/paging/LegacyPagerTest.kt
index 3d42cc6..c2f10b2 100644
--- a/paging/common/src/test/kotlin/androidx/paging/LegacyPagerTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/LegacyPagerTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:Suppress("DEPRECATION")
+
package androidx.paging
import androidx.paging.PagedList.Config
diff --git a/paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt b/paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt
index 3c9cf2e..26e903d 100644
--- a/paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/LegacyPagingSourceTest.kt
@@ -45,6 +45,7 @@
@Test
fun item() {
+ @Suppress("DEPRECATION")
val dataSource = object : ItemKeyedDataSource<Int, String>() {
override fun loadInitial(
params: LoadInitialParams<Int>,
@@ -78,6 +79,7 @@
@Test
fun page() {
+ @Suppress("DEPRECATION")
val dataSource = object : PageKeyedDataSource<Int, String>() {
override fun loadInitial(
params: LoadInitialParams<Int>,
@@ -182,6 +184,7 @@
assertTrue { dataSource.isInvalid }
}
+ @Suppress("DEPRECATION")
private fun createTestPositionalDataSource() = object : PositionalDataSource<String>() {
override fun loadInitial(
params: LoadInitialParams,
diff --git a/paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt b/paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt
index 9d9138d..5ddb98c 100644
--- a/paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/PageKeyedDataSourceTest.kt
@@ -112,6 +112,7 @@
assertEquals(ITEM_LIST, pagedList)
}
+ @Suppress("DEPRECATION")
private fun performLoadInitial(
invalidateDataSource: Boolean = false,
callbackInvoker:
@@ -211,6 +212,7 @@
@Test
fun testBoundaryCallback() {
+ @Suppress("DEPRECATION")
val dataSource = object : PageKeyedDataSource<String, String>() {
override fun loadInitial(
params: LoadInitialParams<String>,
@@ -236,7 +238,7 @@
}
}
- @Suppress("UNCHECKED_CAST")
+ @Suppress("UNCHECKED_CAST", "DEPRECATION")
val boundaryCallback =
mock(PagedList.BoundaryCallback::class.java) as PagedList.BoundaryCallback<String>
val dispatcher = TestDispatcher()
@@ -264,6 +266,7 @@
@Test
fun testBoundaryCallbackJustInitial() {
+ @Suppress("DEPRECATION")
val dataSource = object : PageKeyedDataSource<String, String>() {
override fun loadInitial(
params: LoadInitialParams<String>,
@@ -288,7 +291,7 @@
}
}
- @Suppress("UNCHECKED_CAST")
+ @Suppress("UNCHECKED_CAST", "DEPRECATION")
val boundaryCallback =
mock(PagedList.BoundaryCallback::class.java) as PagedList.BoundaryCallback<String>
val dispatcher = TestDispatcher()
@@ -314,6 +317,7 @@
verifyNoMoreInteractions(boundaryCallback)
}
+ @Suppress("DEPRECATION")
private abstract class WrapperDataSource<K : Any, A : Any, B : Any>(
private val source: PageKeyedDataSource<K, A>
) : PageKeyedDataSource<K, B>() {
@@ -378,6 +382,7 @@
protected abstract fun convert(source: List<A>): List<B>
}
+ @Suppress("DEPRECATION")
private class StringWrapperDataSource<K : Any, V : Any>(source: PageKeyedDataSource<K, V>) :
WrapperDataSource<K, V, String>(source) {
override fun convert(source: List<V>): List<String> {
@@ -385,6 +390,7 @@
}
}
+ @Suppress("DEPRECATION")
private fun verifyWrappedDataSource(
createWrapper: (PageKeyedDataSource<String, Item>) -> PageKeyedDataSource<String, String>
) {
diff --git a/paging/common/src/test/kotlin/androidx/paging/PagedListConfigTest.kt b/paging/common/src/test/kotlin/androidx/paging/PagedListConfigTest.kt
index 49e0ce2..6746965 100644
--- a/paging/common/src/test/kotlin/androidx/paging/PagedListConfigTest.kt
+++ b/paging/common/src/test/kotlin/androidx/paging/PagedListConfigTest.kt
@@ -30,6 +30,7 @@
assertEquals(30, config.initialLoadSizeHint)
assertEquals(true, config.enablePlaceholders)
assertEquals(10, config.prefetchDistance)
+ @Suppress("DEPRECATION")
assertEquals(PagedList.Config.MAX_SIZE_UNBOUNDED, config.maxSize)
}
}
diff --git a/paging/rxjava2/src/test/java/androidx/paging/RxPagedListBuilderTest.kt b/paging/rxjava2/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
index a6e2783..98e99b6 100644
--- a/paging/rxjava2/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
+++ b/paging/rxjava2/src/test/java/androidx/paging/RxPagedListBuilderTest.kt
@@ -105,6 +105,7 @@
.setFetchScheduler(scheduler)
.setNotifyScheduler(scheduler)
.buildObservable()
+ @Suppress("DEPRECATION")
val observer = TestObserver<PagedList<String>>()
observable.subscribe(observer)
@@ -138,6 +139,7 @@
.setFetchScheduler(fetchScheduler)
.setNotifyScheduler(notifyScheduler)
.buildObservable()
+ @Suppress("DEPRECATION")
val observer = TestObserver<PagedList<String>>()
observable.subscribe(observer)
@@ -169,6 +171,7 @@
.setNotifyScheduler(notifyScheduler)
.buildObservable()
+ @Suppress("DEPRECATION")
val observer = TestObserver<PagedList<String>>()
observable.subscribe(observer)
diff --git a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
index cea78ba..355281c 100644
--- a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
@@ -18,7 +18,6 @@
import COMMON
import androidx.paging.DataSource
-import androidx.paging.PositionalDataSource
import androidx.room.Entity
import androidx.room.ext.GuavaUtilConcurrentTypeNames
import androidx.room.ext.L
@@ -406,8 +405,9 @@
fun findPositionalDataSource() {
simpleRun {
invocation ->
+ @Suppress("DEPRECATION")
val dataSource = invocation.processingEnv.elementUtils
- .getTypeElement(PositionalDataSource::class.java.canonicalName)
+ .getTypeElement(androidx.paging.PositionalDataSource::class.java.canonicalName)
assertThat(dataSource, notNullValue())
assertThat(DataSourceQueryResultBinderProvider(invocation.context).matches(
MoreTypes.asDeclared(dataSource.asType())), `is`(true))
diff --git a/ui/ui-animation-core/src/test/java/androidx/animation/TypeConverterTest.kt b/ui/ui-animation-core/src/test/java/androidx/animation/TypeConverterTest.kt
index fab8207..7753e3f 100644
--- a/ui/ui-animation-core/src/test/java/androidx/animation/TypeConverterTest.kt
+++ b/ui/ui-animation-core/src/test/java/androidx/animation/TypeConverterTest.kt
@@ -16,7 +16,7 @@
package androidx.animation
-import junit.framework.Assert.assertEquals
+import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
diff --git a/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidAutofillTest.kt b/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidAutofillTest.kt
index 553974f..75eab0a 100644
--- a/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidAutofillTest.kt
+++ b/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidAutofillTest.kt
@@ -53,6 +53,7 @@
@Before
fun setup() {
+ @Suppress("DEPRECATION") // Robolectric.setupActivity is deprecated
val activity = Robolectric.setupActivity(Activity::class.java)
view = View(activity)
activity.setContentView(view)
diff --git a/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPerformAutofillTest.kt b/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPerformAutofillTest.kt
index f559223..582d792 100644
--- a/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPerformAutofillTest.kt
+++ b/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPerformAutofillTest.kt
@@ -41,6 +41,7 @@
@Before
fun setup() {
+ @Suppress("DEPRECATION") // Robolectric.setupActivity is deprecated
val activity = Robolectric.setupActivity(Activity::class.java)
val view = View(activity)
activity.setContentView(view)
diff --git a/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPopulateViewStructureTest.kt b/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPopulateViewStructureTest.kt
index 9071352..41efdf0 100644
--- a/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPopulateViewStructureTest.kt
+++ b/ui/ui-platform/src/test/java/androidx/ui/autofill/AndroidPopulateViewStructureTest.kt
@@ -42,6 +42,7 @@
@Before
fun setup() {
+ @Suppress("DEPRECATION") // Robolectric.setupActivity is deprecated
val activity = Robolectric.setupActivity(Activity::class.java)
val view = View(activity)
activity.setContentView(view)
diff --git a/ui/ui-platform/src/test/java/androidx/ui/core/pointerinput/PointerInputEventProcessorTest.kt b/ui/ui-platform/src/test/java/androidx/ui/core/pointerinput/PointerInputEventProcessorTest.kt
index 613f792..b865ba7 100644
--- a/ui/ui-platform/src/test/java/androidx/ui/core/pointerinput/PointerInputEventProcessorTest.kt
+++ b/ui/ui-platform/src/test/java/androidx/ui/core/pointerinput/PointerInputEventProcessorTest.kt
@@ -1930,7 +1930,6 @@
// Arrange
val pointerInputFilter: PointerInputFilter = spy()
- val cancelHandler: () -> Unit = spy()
val layoutNode = LayoutNode(
0, 0, 500, 500,
PointerInputModifierImpl(pointerInputFilter)
diff --git a/work/workmanager-ktx/build.gradle b/work/workmanager-ktx/build.gradle
index c1a1a67..3ebe3d0 100644
--- a/work/workmanager-ktx/build.gradle
+++ b/work/workmanager-ktx/build.gradle
@@ -18,6 +18,7 @@
import androidx.build.LibraryGroups
import androidx.build.LibraryVersions
import androidx.build.AndroidXExtension
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import static androidx.build.dependencies.DependenciesKt.*
import androidx.build.Publish
@@ -65,3 +66,11 @@
description = "Android WorkManager Kotlin Extensions"
url = AndroidXExtension.ARCHITECTURE_URL
}
+
+
+// Allow usage of Kotlin's @OptIn.
+tasks.withType(KotlinCompile).configureEach {
+ kotlinOptions {
+ freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
+ }
+}
diff --git a/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt b/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt
index 1f87734..5f26e92 100644
--- a/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt
+++ b/work/workmanager-ktx/src/androidTest/java/androidx/work/ListenableFutureTest.kt
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
+
package androidx.work
import androidx.concurrent.futures.ResolvableFuture
diff --git a/work/workmanager-rxjava2/src/test/java/androidx/work/SetCompletableProgressTest.kt b/work/workmanager-rxjava2/src/test/java/androidx/work/SetCompletableProgressTest.kt
index a1bd9fc..c5b98f8 100644
--- a/work/workmanager-rxjava2/src/test/java/androidx/work/SetCompletableProgressTest.kt
+++ b/work/workmanager-rxjava2/src/test/java/androidx/work/SetCompletableProgressTest.kt
@@ -20,7 +20,7 @@
import androidx.work.ListenableWorker.Result
import androidx.work.impl.utils.SynchronousExecutor
import androidx.work.impl.utils.futures.SettableFuture
-import junit.framework.Assert.assertEquals
+import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith