Repository: apollographql/apollo-kotlin
Pull request #4666 (2023-02-02 14:42:09)

allWarningsAsErrors 
Enable `allWarningsAsErrors` except for:
* the `requires-opt-in-deprecated` integration test that has some warnings in generated code that we can't suppress (we should maybe allow to customize this?)
* the `compile${foo}KotlinMetadata` that fail to find SQLiter libs and other things. Given that HMPP is pretty much under work, I found it easier to ignore them 

That's mostly it. Everything else is warning free at the price of some `@Suppress("UNUSED_VARIABLE")` in the integration tests

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *apollo-android-docs* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 22fb3b0fffd29c5aac20015b4da27e630ab009b7 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apollo-android-docs/deploys/63dbcbc3ef4b90000930ab31 |

Patch:
diff --git a/build-logic/src/main/kotlin/CompilerOptions.kt b/build-logic/src/main/kotlin/CompilerOptions.kt
index 7ae0faf723..2542892d56 100644
--- a/build-logic/src/main/kotlin/CompilerOptions.kt
+++ b/build-logic/src/main/kotlin/CompilerOptions.kt
@@ -2,17 +2,17 @@ import org.gradle.api.Project
 import org.gradle.api.plugins.JavaPluginExtension
 import org.gradle.api.tasks.compile.JavaCompile
 import org.gradle.jvm.toolchain.JavaLanguageVersion
+import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
+import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
 import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
 
-fun Project.configureJavaAndKotlinCompilers(treatWarningsAsErrors: Boolean = false) {
+fun Project.configureJavaAndKotlinCompilers() {
   // For Kotlin JVM projects
-  tasks.withType(KotlinCompile::class.java) {
+  tasks.withType(KotlinCompile::class.java).configureEach {
     kotlinOptions {
       freeCompilerArgs = freeCompilerArgs + listOf(
           "-opt-in=kotlin.RequiresOptIn",
-          "-opt-in=com.apollographql.apollo3.annotations.ApolloExperimental",
-          "-opt-in=com.apollographql.apollo3.annotations.ApolloInternal"
       )
       if (getKotlinPluginVersion() == "1.6.10") {
         // This is a workaround for https://youtrack.jetbrains.com/issue/KT-47000 (fixed in Kotlin 1.6.20)
@@ -24,7 +24,13 @@ fun Project.configureJavaAndKotlinCompilers(treatWarningsAsErrors: Boolean = fal
       }
       apiVersion = "1.5"
       languageVersion = "1.5"
-      jvmTarget = "1.8"
+
+      (this as? KotlinJvmOptions)?.jvmTarget = "1.8"
+    }
+  }
+  tasks.withType(KotlinNativeCompile::class.java).configureEach {
+    kotlinOptions {
+      this.freeCompilerArgs += "-opt-in=kotlinx.cinterop.UnsafeNumber"
     }
   }
 
@@ -50,13 +56,32 @@ fun Project.configureJavaAndKotlinCompilers(treatWarningsAsErrors: Boolean = fal
     options.release.set(8)
   }
 
-  if (treatWarningsAsErrors) treatWarningsAsErrors()
+  allWarningsAsErrors(true)
+}
+
+internal fun Project.optIn(vararg annotations: String) {
+  tasks.withType(KotlinCompile::class.java).configureEach {
+    kotlinOptions {
+      freeCompilerArgs = freeCompilerArgs + annotations.map { "-opt-in=$it" }
+    }
+  }
 }
 
-private fun Project.treatWarningsAsErrors() {
-  tasks.withType(KotlinCompile::class.java) {
+fun Project.allWarningsAsErrors(allWarningsAsErrors: Boolean) {
+  tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
     kotlinOptions {
-      allWarningsAsErrors = true
+      if (this@configureEach.name.endsWith("KotlinMetadata")) {
+        /**
+         * KotlinMetadata compilations trigger warnings such as below:
+         *
+         * w: Could not find "co.touchlab:sqliter-driver-cinterop-sqlite3" in [/Users/mbonnin/git/reproducer-apple-metadata, /Users/mbonnin/.konan/klib, /Users/mbonnin/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.0/klib/common, /Users/mbonnin/.konan/kotlin-native-prebuilt-macos-aarch64-1.8.0/klib/platform/macos_arm64]
+         *
+         * I'm thinking it has to do with HMPP but not 100% yet. Ignore all warnings in these tasks
+         */
+        this.allWarningsAsErrors = false
+      } else {
+        this.allWarningsAsErrors = allWarningsAsErrors
+      }
     }
   }
 }
diff --git a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt
index 15a9522d39..db79c9e11d 100644
--- a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt
+++ b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/LibraryConventionPlugin.kt
@@ -4,13 +4,13 @@ import configureJavaAndKotlinCompilers
 import configureMppDefaults
 import configurePublishing
 import configureTesting
+import optIn
 import org.gradle.api.Action
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.provider.Property
 import org.gradle.api.tasks.Nested
 import org.gradle.api.tasks.bundling.Jar
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 
 class LibraryConventionPlugin : Plugin<Project> {
   override fun apply(project: Project) {
@@ -20,7 +20,11 @@ class LibraryConventionPlugin : Plugin<Project> {
 
       extensions.create("apolloLibrary", Extension::class.java)
 
-      configureJavaAndKotlinCompilers(treatWarningsAsErrors = true)
+      configureJavaAndKotlinCompilers()
+      optIn(
+          "com.apollographql.apollo3.annotations.ApolloExperimental",
+          "com.apollographql.apollo3.annotations.ApolloInternal"
+      )
 
       configureTesting()
 
@@ -54,13 +58,5 @@ class LibraryConventionPlugin : Plugin<Project> {
         }
       }
     }
-
-    fun treatWarningsAsErrors(treatWarningsAsErrors: Boolean) {
-      project.tasks.withType(KotlinCompile::class.java).configureEach {
-        kotlinOptions {
-          allWarningsAsErrors = treatWarningsAsErrors
-        }
-      }
-    }
   }
 }
diff --git a/docs/source/migration/4.0.mdx b/docs/source/migration/4.0.mdx
new file mode 100644
index 0000000000..272d0ff11b
--- /dev/null
+++ b/docs/source/migration/4.0.mdx
@@ -0,0 +1,7 @@
+---
+title: Migrating to Apollo Kotlin 4.0
+description: From 3.x
+---
+
+* Requires Kotlin 1.5+
+* Dropped `enableCompatibilityMetadataVariant`
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index 21531b33a3..85121d1855 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -16,11 +16,6 @@ POM_DEVELOPER_NAME=Apollo
 
 android.useAndroidX=true
 
-
-# Enable compatibility with non-hierarchical projects.
-# See https://kotlinlang.org/docs/multiplatform-hierarchy.html#for-library-authors
-kotlin.mpp.enableCompatibilityMetadataVariant=true
-
 # Keep in sync with other projects
 # Give more memory to the Gradle daemon
 org.gradle.jvmargs=-Xmx8g
diff --git a/gradle/libraries.toml b/gradle/libraries.toml
index aecffcf5cb..7c1cae8172 100644
--- a/gradle/libraries.toml
+++ b/gradle/libraries.toml
@@ -60,6 +60,7 @@ apollo-normalizedcache-sqlite = { group = "com.apollographql.apollo3", name = "a
 apollo-normalizedcache-sqlite-incubating = { group = "com.apollographql.apollo3", name = "apollo-normalized-cache-sqlite-incubating", version.ref = "apollo" }
 apollo-plugin = { group = "com.apollographql.apollo3", name = "apollo-gradle-plugin", version.ref = "apollo" }
 apollo-runtime = { group = "com.apollographql.apollo3", name = "apollo-runtime", version.ref = "apollo" }
+apollo-annotations = { group = "com.apollographql.apollo3", name = "apollo-annotations", version.ref = "apollo" }
 apollo-runtime-java = { group = "com.apollographql.apollo3", name = "apollo-runtime-java", version.ref = "apollo" }
 apollo-rx2 = { group = "com.apollographql.apollo3", name = "apollo-rx2-support", version.ref = "apollo" }
 apollo-rx3-java = { group = "com.apollographql.apollo3", name = "apollo-rx3-support-java", version.ref = "apollo" }
diff --git a/libraries/apollo-adapters/src/appleMain/kotlin/com/apollographql/apollo3/adapter/BigDecimal.kt b/libraries/apollo-adapters/src/appleMain/kotlin/com/apollographql/apollo3/adapter/BigDecimal.kt
index 335636d5c4..5a146787f7 100644
--- a/libraries/apollo-adapters/src/appleMain/kotlin/com/apollographql/apollo3/adapter/BigDecimal.kt
+++ b/libraries/apollo-adapters/src/appleMain/kotlin/com/apollographql/apollo3/adapter/BigDecimal.kt
@@ -23,7 +23,6 @@ actual class BigDecimal internal constructor(private val raw: NSDecimalNumber) :
   actual fun negate(): BigDecimal = BigDecimal(NSDecimalNumber(int = 0).decimalNumberBySubtracting(raw))
 
   actual fun signum(): Int {
-    @OptIn(kotlinx.cinterop.UnsafeNumber::class)
     val result = raw.compare(NSDecimalNumber(int = 0)).toInt()
     return when {
       result < 0 -> -1
diff --git a/libraries/apollo-annotations/build.gradle.kts b/libraries/apollo-annotations/build.gradle.kts
index 2c40ea52c4..74c51e323a 100644
--- a/libraries/apollo-annotations/build.gradle.kts
+++ b/libraries/apollo-annotations/build.gradle.kts
@@ -25,4 +25,3 @@ kotlin {
     }
   }
 }
-
diff --git a/libraries/apollo-gradle-plugin-external/build.gradle.kts b/libraries/apollo-gradle-plugin-external/build.gradle.kts
index b2475ec9bd..0c8ae2ae80 100644
--- a/libraries/apollo-gradle-plugin-external/build.gradle.kts
+++ b/libraries/apollo-gradle-plugin-external/build.gradle.kts
@@ -6,7 +6,7 @@ plugins {
 }
 
 apolloLibrary {
-  treatWarningsAsErrors(false)
+  javaModuleName("com.apollographql.apollo3.gradle")
 }
 
 dependencies {
@@ -19,7 +19,6 @@ dependencies {
   implementation(project(":apollo-ast"))
 }
 
-
 gradlePlugin {
   plugins {
     create("apolloGradlePlugin") {
diff --git a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultDirectoryConnection.kt b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultDirectoryConnection.kt
index b18ee4f185..f557f6416a 100644
--- a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultDirectoryConnection.kt
+++ b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultDirectoryConnection.kt
@@ -30,6 +30,7 @@ internal class DefaultDirectoryConnection(
     connectToAndroidVariant(project, variant, outputDir, task)
   }
 
+  @Deprecated("This method doesn't mark the sources as generated. This confuses some tools like lint that might do extra work on the generated files", replaceWith = ReplaceWith("connectToAndroidVariant(variant)"))
   override fun connectToAndroidSourceSet(name: String) {
     connectToAndroidSourceSet(project, name, outputDir, task)
   }
diff --git a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt
index fd326387f8..7e3cf9c568 100644
--- a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt
+++ b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultService.kt
@@ -21,6 +21,7 @@ abstract class DefaultService @Inject constructor(val project: Project, override
 
   init {
     @Suppress("LeakingThis")
+    @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
     if (GradleVersion.current() >= GradleVersion.version("6.2")) {
       // This allows users to call includes.put("Date", "java.util.Date")
       // see https://github.com/gradle/gradle/issues/7485
diff --git a/libraries/apollo-gradle-plugin/build.gradle.kts b/libraries/apollo-gradle-plugin/build.gradle.kts
index c2911f3126..458de257f4 100644
--- a/libraries/apollo-gradle-plugin/build.gradle.kts
+++ b/libraries/apollo-gradle-plugin/build.gradle.kts
@@ -7,7 +7,6 @@ plugins {
 }
 
 apolloLibrary {
-  treatWarningsAsErrors(true)
 }
 
 // Configuration for extra jar to pass to R8 to give it more context about what can be relocated
diff --git a/libraries/apollo-mockserver/build.gradle.kts b/libraries/apollo-mockserver/build.gradle.kts
index e814eb3971..1628e2a172 100644
--- a/libraries/apollo-mockserver/build.gradle.kts
+++ b/libraries/apollo-mockserver/build.gradle.kts
@@ -33,6 +33,11 @@ kotlin {
       dependencies {
         implementation(project(":apollo-testing-support")) {
           because("runTest")
+          // We have a circular dependency here that creates a warning in JS
+          // w: duplicate library name: com.apollographql.apollo3:apollo-mockserver
+          // See https://youtrack.jetbrains.com/issue/KT-51110
+          // We should probably remove this circular dependency but for the time being, just use excludes
+          exclude(group =  "com.apollographql.apollo3", module = "apollo-mockserver")
         }
         implementation(project(":apollo-runtime")) {
           because("We need HttpEngine for SocketTest")
diff --git a/libraries/apollo-mockserver/src/appleMain/kotlin/com/apollographql/apollo3/mockserver/FileDescriptorSink.kt b/libraries/apollo-mockserver/src/appleMain/kotlin/com/apollographql/apollo3/mockserver/FileDescriptorSink.kt
index a9d7422ec1..7ada050bcd 100644
--- a/libraries/apollo-mockserver/src/appleMain/kotlin/com/apollographql/apollo3/mockserver/FileDescriptorSink.kt
+++ b/libraries/apollo-mockserver/src/appleMain/kotlin/com/apollographql/apollo3/mockserver/FileDescriptorSink.kt
@@ -2,12 +2,10 @@ package com.apollographql.apollo3.mockserver
 
 import kotlinx.cinterop.ByteVar
 import kotlinx.cinterop.CArrayPointer
-import kotlinx.cinterop.allocArray
 import kotlinx.cinterop.allocArrayOf
 import kotlinx.cinterop.convert
 import kotlinx.cinterop.memScoped
 import kotlinx.cinterop.plus
-import kotlinx.cinterop.readBytes
 import okio.Buffer
 import okio.IOException
 import okio.Sink
diff --git a/libraries/apollo-runtime/build.gradle.kts b/libraries/apollo-runtime/build.gradle.kts
index 29b9f601fd..d2e3a244dd 100644
--- a/libraries/apollo-runtime/build.gradle.kts
+++ b/libraries/apollo-runtime/build.gradle.kts
@@ -25,7 +25,14 @@ kotlin {
     findByName("commonTest")?.apply {
       dependencies {
         implementation(project(":apollo-mockserver"))
-        implementation(project(":apollo-testing-support"))
+        implementation(project(":apollo-testing-support")) {
+          because("runTest")
+          // We have a circular dependency here that creates a warning in JS
+          // w: duplicate library name: com.apollographql.apollo3:apollo-mockserver
+          // See https://youtrack.jetbrains.com/issue/KT-51110
+          // We should probably remove this circular dependency but for the time being, just use excludes
+          exclude(group =  "com.apollographql.apollo3", module = "apollo-runtime")
+        }
       }
     }
 


Test patch:
diff --git a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt
index b12eecaeb3..771e8883a4 100644
--- a/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt
+++ b/build-logic/src/main/kotlin/com/apollographql/apollo3/buildlogic/plugin/TestConventionPlugin.kt
@@ -3,6 +3,7 @@ package com.apollographql.apollo3.buildlogic.plugin
 import configureJavaAndKotlinCompilers
 import configureMppTestsDefaults
 import configureTesting
+import optIn
 import org.gradle.api.Action
 import org.gradle.api.Plugin
 import org.gradle.api.Project
@@ -16,6 +17,10 @@ class TestConventionPlugin : Plugin<Project> {
       extensions.create("apolloTest", Extension::class.java)
 
       configureJavaAndKotlinCompilers()
+      optIn(
+          "com.apollographql.apollo3.annotations.ApolloExperimental",
+          "com.apollographql.apollo3.annotations.ApolloInternal", // for runTest
+      )
 
       configureTesting()
     }
diff --git a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateUsedCoordinatesTask.kt b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateUsedCoordinatesTask.kt
index 42ba8eab51..bb973e2d44 100644
--- a/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateUsedCoordinatesTask.kt
+++ b/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateUsedCoordinatesTask.kt
@@ -2,12 +2,10 @@ package com.apollographql.apollo3.gradle.internal
 
 import com.apollographql.apollo3.ast.introspection.toSchema
 import com.apollographql.apollo3.compiler.ApolloCompiler
-import com.apollographql.apollo3.compiler.ApolloMetadata
 import com.apollographql.apollo3.compiler.IncomingOptions.Companion.resolveSchema
 import org.gradle.api.DefaultTask
 import org.gradle.api.file.ConfigurableFileCollection
 import org.gradle.api.file.RegularFileProperty
-import org.gradle.api.model.ObjectFactory
 import org.gradle.api.provider.ListProperty
 import org.gradle.api.tasks.CacheableTask
 import org.gradle.api.tasks.Input
@@ -17,7 +15,6 @@ import org.gradle.api.tasks.OutputFile
 import org.gradle.api.tasks.PathSensitive
 import org.gradle.api.tasks.PathSensitivity
 import org.gradle.api.tasks.TaskAction
-import javax.inject.Inject
 
 @CacheableTask
 abstract class ApolloGenerateUsedCoordinatesTask : DefaultTask() {
@@ -50,7 +47,7 @@ abstract class ApolloGenerateUsedCoordinatesTask : DefaultTask() {
         "Apollo: multiple incoming schemas"
       }
 
-      var schema = schemas?.singleOrNull()
+      var schema = schemas.singleOrNull()
       if (schema == null) {
         schema = resolveSchema(schemaFiles.files, rootFolders.get()).first
       }
diff --git a/libraries/apollo-testing-support/src/appleMain/kotlin/com/apollographql/apollo3/testing/cwd.kt b/libraries/apollo-testing-support/src/appleMain/kotlin/com/apollographql/apollo3/testing/cwd.kt
index 962f482448..e80c93b359 100644
--- a/libraries/apollo-testing-support/src/appleMain/kotlin/com/apollographql/apollo3/testing/cwd.kt
+++ b/libraries/apollo-testing-support/src/appleMain/kotlin/com/apollographql/apollo3/testing/cwd.kt
@@ -11,7 +11,6 @@ fun cwd(): String {
   return memScoped {
     val maxSize = 1024
     val buf = allocArray<ByteVar>(maxSize)
-    @OptIn(kotlinx.cinterop.UnsafeNumber::class)
     getcwd(buf, maxSize.convert())?.toKString() ?: "?"
   }
 }
\ No newline at end of file
diff --git a/tests/compiler-hooks/src/test/kotlin/test/PrefixNamesTest.kt b/tests/compiler-hooks/src/test/kotlin/test/PrefixNamesTest.kt
index 5e29e5e219..52bdc9623e 100644
--- a/tests/compiler-hooks/src/test/kotlin/test/PrefixNamesTest.kt
+++ b/tests/compiler-hooks/src/test/kotlin/test/PrefixNamesTest.kt
@@ -4,6 +4,7 @@ import hooks.prefixnames.kotlin.GQLNodeQuery
 import hooks.prefixnames.kotlin.type.GQLJob
 import org.junit.Test
 
+@Suppress("UNUSED_VARIABLE")
 class PrefixNamesTest {
   @Test
   fun kotlinPrefixNames() {
diff --git a/tests/compiler-hooks/src/test/kotlin/test/TypeNameInterfaceTest.kt b/tests/compiler-hooks/src/test/kotlin/test/TypeNameInterfaceTest.kt
index c26f43e22d..405680ff0d 100644
--- a/tests/compiler-hooks/src/test/kotlin/test/TypeNameInterfaceTest.kt
+++ b/tests/compiler-hooks/src/test/kotlin/test/TypeNameInterfaceTest.kt
@@ -6,6 +6,7 @@ import hooks.typenameinterface.UserQuery
 import hooks.typenameinterface.fragment.UserFragment
 import org.junit.Test
 
+@Suppress("UNUSED_VARIABLE")
 class TypeNameInterfaceTest {
   @Test
   fun typeNameInterface() {
diff --git a/tests/data-builders-kotlin/src/test/kotlin/test/DataBuilderTest.kt b/tests/data-builders-kotlin/src/test/kotlin/test/DataBuilderTest.kt
index f36ea74d15..703c69c6ac 100644
--- a/tests/data-builders-kotlin/src/test/kotlin/test/DataBuilderTest.kt
+++ b/tests/data-builders-kotlin/src/test/kotlin/test/DataBuilderTest.kt
@@ -238,7 +238,7 @@ class DataBuilderTest {
 
   class MyFakeResolver : DefaultFakeResolver(__Schema.all) {
     override fun resolveLeaf(context: FakeResolverContext): Any {
-      return when (val name = context.mergedField.type.rawType().name) {
+      return when (context.mergedField.type.rawType().name) {
         "Long1" -> MyLong(45) // build-time
         "Long2" -> MyLong(46) // run-time
         "Long3" -> 47L // mapped to Any
diff --git a/tests/deprecated-requires-opt-in/README.md b/tests/deprecated-requires-opt-in/README.md
index 47b267a06e..d790fd835f 100644
--- a/tests/deprecated-requires-opt-in/README.md
+++ b/tests/deprecated-requires-opt-in/README.md
@@ -1,1 +1,1 @@
-Test for `@deprecated` and `@experimental`
\ No newline at end of file
+Test for `@deprecated` and `@requiresOptIn`
\ No newline at end of file
diff --git a/tests/deprecated-requires-opt-in/build.gradle.kts b/tests/deprecated-requires-opt-in/build.gradle.kts
index fe8c8a00d6..b7b0a672cd 100644
--- a/tests/deprecated-requires-opt-in/build.gradle.kts
+++ b/tests/deprecated-requires-opt-in/build.gradle.kts
@@ -10,6 +10,17 @@ dependencies {
   testImplementation(golatac.lib("junit"))
 }
 
+/**
+ * Because of:
+ *
+ * w: file:///Users/mbonnin/git/apollo-kotlin/tests/deprecated-requires-opt-in/build/generated/source/apollo/custom/custom/adapter/GetNewFieldQuery_ResponseAdapter.kt:51:76 'oldField: Direction' is deprecated. No longer supported
+ * w: file:///Users/mbonnin/git/apollo-kotlin/tests/deprecated-requires-opt-in/build/generated/source/apollo/default/default/adapter/GetNewFieldQuery_ResponseAdapter.kt:51:76 'oldField: Direction' is deprecated. No longer supported
+ * w: file:///Users/mbonnin/git/apollo-kotlin/tests/deprecated-requires-opt-in/build/generated/source/apollo/none/none/adapter/GetNewFieldQuery_ResponseAdapter.kt:51:76 'oldField: Direction' is deprecated. No longer supported
+ *
+ * This is in generated code, the only way to remove these warnings is to remove the field usage which we can't do here so we just ignore warnings
+ */
+allWarningsAsErrors(false)
+
 apollo {
   service("default") {
     srcDir("graphql")
@@ -26,3 +37,4 @@ apollo {
     packageName.set("custom")
   }
 }
+
diff --git a/tests/deprecated-requires-opt-in/src/test/kotlin/test/RequiresOptInTest.kt b/tests/deprecated-requires-opt-in/src/test/kotlin/test/RequiresOptInTest.kt
index ae0cc3b43b..b5c56b74a1 100644
--- a/tests/deprecated-requires-opt-in/src/test/kotlin/test/RequiresOptInTest.kt
+++ b/tests/deprecated-requires-opt-in/src/test/kotlin/test/RequiresOptInTest.kt
@@ -2,22 +2,20 @@ package test
 
 import com.apollographql.apollo3.annotations.ApolloRequiresOptIn
 import com.apollographql.apollo3.api.Optional
-import none.GetNewFieldQuery as GetNewFieldQueryNone
-import default.GetNewFieldQuery as GetNewFieldQueryDefault
-import custom.GetNewFieldQuery as GetNewFieldQueryCustom
-
-import none.type.Direction as DirectionNone
-import default.type.Direction as DirectionDefault
-import custom.type.Direction as DirectionCustom
-
-import none.type.SomeInput as SomeInputNone
-import default.type.SomeInput as SomeInputDefault
-import custom.type.SomeInput as SomeInputCustom
-
 import org.junit.Test
 import kotlin.test.assertFalse
 import kotlin.test.assertTrue
+import custom.GetNewFieldQuery as GetNewFieldQueryCustom
+import custom.type.Direction as DirectionCustom
+import custom.type.SomeInput as SomeInputCustom
+import default.GetNewFieldQuery as GetNewFieldQueryDefault
+import default.type.Direction as DirectionDefault
+import default.type.SomeInput as SomeInputDefault
+import none.GetNewFieldQuery as GetNewFieldQueryNone
+import none.type.Direction as DirectionNone
+import none.type.SomeInput as SomeInputNone
 
+@Suppress("DEPRECATION")
 class RequiresOptInTest {
   /**
    * Visual test: this allows to see how the annotation is used but doesn't actually test anything
diff --git a/tests/enums/src/test/kotlin/test/EnumsTest.kt b/tests/enums/src/test/kotlin/test/EnumsTest.kt
index 5fba7faa9c..9d8c06a39d 100644
--- a/tests/enums/src/test/kotlin/test/EnumsTest.kt
+++ b/tests/enums/src/test/kotlin/test/EnumsTest.kt
@@ -12,6 +12,7 @@ class EnumsTest {
   @Test
   fun kotlinEnums() {
     assertEquals(Direction.NORTH, Direction.safeValueOf("NORTH"))
+    @Suppress("DEPRECATION")
     assertEquals(Direction.north, Direction.safeValueOf("north"))
     assertEquals(Direction.UNKNOWN__, Direction.safeValueOf("newDirection"))
     assertEquals(Direction.name_, Direction.safeValueOf("name"))
@@ -23,6 +24,7 @@ class EnumsTest {
   @Test
   fun kotlinSealedClasses() {
     assertEquals(Gravity.TOP, Gravity.safeValueOf("TOP"))
+    @Suppress("DEPRECATION")
     assertEquals(Gravity.top2, Gravity.safeValueOf("top2"))
     assertEquals(Gravity.UNKNOWN__("newGravity"), Gravity.safeValueOf("newGravity"))
     assertEquals(Gravity.name, Gravity.safeValueOf("name"))
@@ -34,6 +36,7 @@ class EnumsTest {
   @Test
   fun javaEnums() {
     assertEquals(enums.java.type.Direction.NORTH, enums.java.type.Direction.safeValueOf("NORTH"))
+    @Suppress("DEPRECATION")
     assertEquals(enums.java.type.Direction.north, enums.java.type.Direction.safeValueOf("north"))
     assertEquals(enums.java.type.Direction.UNKNOWN__, enums.java.type.Direction.safeValueOf("newDirection"))
     assertEquals(enums.java.type.Direction.name, enums.java.type.Direction.safeValueOf("name"))
@@ -73,6 +76,7 @@ class EnumsTest {
     // knownValues() should return the same order that the values are declared in the schema
     // Convert to List because Array.equals uses referential equality, see
     // https://blog.jetbrains.com/kotlin/2015/09/feedback-request-limitations-on-data-classes/
+    @Suppress("DEPRECATION")
     assertEquals(
         arrayOf(
             Gravity.TOP,
diff --git a/tests/escaping/src/test/kotlin/test/EscapingTest.kt b/tests/escaping/src/test/kotlin/test/EscapingTest.kt
index 55c8ec7da6..8f89a64a0e 100644
--- a/tests/escaping/src/test/kotlin/test/EscapingTest.kt
+++ b/tests/escaping/src/test/kotlin/test/EscapingTest.kt
@@ -18,7 +18,10 @@ class EscapingTest {
         ))
         .execute()
     val `while`: WhileQuery.While? = response.dataAssertNoErrors.`while`
+
+    @Suppress("UNUSED_VARIABLE")
     val `if`: String? = `while`?.`if`
+    @Suppress("UNUSED_VARIABLE")
     val `else`: String? = `while`?.`else`
   }
 }
diff --git a/tests/integration-tests/src/commonTest/kotlin/test/circular_cache_read/CircularCacheReadTest.kt b/tests/integration-tests/src/commonTest/kotlin/test/circular_cache_read/CircularCacheReadTest.kt
index ff77db4992..c505fe809d 100644
--- a/tests/integration-tests/src/commonTest/kotlin/test/circular_cache_read/CircularCacheReadTest.kt
+++ b/tests/integration-tests/src/commonTest/kotlin/test/circular_cache_read/CircularCacheReadTest.kt
@@ -31,6 +31,6 @@ class CircularCacheReadTest {
 
     store.writeOperation(operation, data)
     val result = store.readOperation(operation, customScalarAdapters = CustomScalarAdapters.Empty)
-    assertEquals("42", result!!.user.friend.id)
+    assertEquals("42", result.user.friend.id)
   }
 }
diff --git a/tests/integration-tests/src/commonTest/kotlin/test/declarativecache/DeclarativeCacheTest.kt b/tests/integration-tests/src/commonTest/kotlin/test/declarativecache/DeclarativeCacheTest.kt
index 99d57d3ce3..2ab4cd3495 100644
--- a/tests/integration-tests/src/commonTest/kotlin/test/declarativecache/DeclarativeCacheTest.kt
+++ b/tests/integration-tests/src/commonTest/kotlin/test/declarativecache/DeclarativeCacheTest.kt
@@ -39,7 +39,7 @@ class DeclarativeCacheTest {
     // Get the "promo" book again, the title must be updated
     val data = store.readOperation(promoOperation, CustomScalarAdapters.Empty)
 
-    assertEquals("Other", data?.promoBook?.title)
+    assertEquals("Other", data.promoBook?.title)
   }
 
   @Test
@@ -59,7 +59,7 @@ class DeclarativeCacheTest {
     // Get the "promo" library again, the address must be updated
     val data = store.readOperation(promoOperation, CustomScalarAdapters.Empty)
 
-    assertEquals("OtherAddress", data?.promoLibrary?.address)
+    assertEquals("OtherAddress", data.promoLibrary?.address)
   }
 
   @Test
@@ -119,12 +119,12 @@ class DeclarativeCacheTest {
     var operation = GetBooksQuery(listOf("4", "1"))
     var data = store.readOperation(operation, CustomScalarAdapters.Empty)
 
-    assertEquals("Title4", data?.books?.get(0)?.title)
-    assertEquals("Title1", data?.books?.get(1)?.title)
+    assertEquals("Title4", data.books.get(0).title)
+    assertEquals("Title1", data.books.get(1).title)
 
     operation = GetBooksQuery(listOf("3"))
     data = store.readOperation(operation, CustomScalarAdapters.Empty)
 
-    assertEquals("Title3", data?.books?.get(0)?.title)
+    assertEquals("Title3", data.books.get(0).title)
   }
 }
diff --git a/tests/integration-tests/src/commonTest/kotlin/test/fake_subscription_engine/SubscriptionTest.kt b/tests/integration-tests/src/commonTest/kotlin/test/fake_subscription_engine/SubscriptionTest.kt
index 2eae475de6..a59f8f6307 100644
--- a/tests/integration-tests/src/commonTest/kotlin/test/fake_subscription_engine/SubscriptionTest.kt
+++ b/tests/integration-tests/src/commonTest/kotlin/test/fake_subscription_engine/SubscriptionTest.kt
@@ -87,6 +87,7 @@ class SubscriptionTest {
   }
 
   private fun String.toMessageMap(): Map<String, Any?>? = try {
+    @Suppress("UNCHECKED_CAST")
     AnyAdapter.fromJson(
         BufferedSourceJsonReader(Buffer().writeUtf8(this)),
         CustomScalarAdapters.Empty
diff --git a/tests/multi-module-3/child/src/test/kotlin/test/MultiModuleDataBuilderTest.kt b/tests/multi-module-3/child/src/test/kotlin/test/MultiModuleDataBuilderTest.kt
index 411e55139b..b4175a4876 100644
--- a/tests/multi-module-3/child/src/test/kotlin/test/MultiModuleDataBuilderTest.kt
+++ b/tests/multi-module-3/child/src/test/kotlin/test/MultiModuleDataBuilderTest.kt
@@ -1,12 +1,14 @@
 package test
 
-import org.junit.Test
 import multimodule3.child.GetAnimalQuery
 import multimodule3.root.type.buildCat
+import org.junit.Test
 
 class MultiModuleDataBuilderTest {
   @Test
   fun test() {
+
+    @Suppress("UNUSED_VARIABLE")
     val data = GetAnimalQuery.Data {
       animal = buildCat {
         species = "cat"
diff --git a/tests/sample-server/build.gradle.kts b/tests/sample-server/build.gradle.kts
index 7c560b8dbf..4de27d2c73 100644
--- a/tests/sample-server/build.gradle.kts
+++ b/tests/sample-server/build.gradle.kts
@@ -7,13 +7,19 @@ plugins {
 
 dependencies {
   implementation(golatac.lib("graphqlkotlin"))
-  implementation(golatac.lib("kotlin.reflect").toString()) {
+  implementation(golatac.lib("kotlin.reflect")) {
     because("graphqlKotlin pull kotlin-reflect and that triggers a warning like" +
         "Runtime JAR files in the classpath should have the same version.")
   }
-  implementation(golatac.lib("kotlinx.coroutines.reactor").toString()) {
+  implementation(golatac.lib("kotlinx.coroutines.reactor")) {
     because("reactor must have the same version as the coroutines version")
   }
+  compileOnly(golatac.lib("apollo.annotations")) {
+    because("""
+      We unconditionally opt-in ApolloExperimental in all the tests and we need the symbol in the 
+      classpath to prevent a warning
+    """.trimIndent())
+  }
 }
 
 application {
diff --git a/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/MyWebSocketHandlerAdapter.kt b/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/MyWebSocketHandlerAdapter.kt
index b16436e535..cbf95bf3bf 100644
--- a/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/MyWebSocketHandlerAdapter.kt
+++ b/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/MyWebSocketHandlerAdapter.kt
@@ -8,8 +8,8 @@ import org.springframework.web.server.ServerWebExchange
 import reactor.core.publisher.Mono
 
 class MyWebSocketHandlerAdapter : WebSocketHandlerAdapter(HandshakeWebSocketService()) {
-  override fun handle(exchange: ServerWebExchange?, handler: Any?): Mono<HandlerResult>? {
-    val webSocketHandler = handler as WebSocketHandler?
+  override fun handle(exchange: ServerWebExchange, handler: Any): Mono<HandlerResult> {
+    val webSocketHandler = handler as WebSocketHandler
     return webSocketService.handleRequest(exchange, webSocketHandler).then(Mono.empty())
   }
 }
diff --git a/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/SampleServer.kt b/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/SampleServer.kt
index cdf77e9577..84b6a856f8 100644
--- a/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/SampleServer.kt
+++ b/tests/sample-server/src/main/kotlin/com/apollographql/apollo/sample/server/SampleServer.kt
@@ -8,16 +8,14 @@ class SampleServer : Closeable {
   private var context = runApplication<DefaultApplication>() as AnnotationConfigReactiveWebServerApplicationContext
 
   fun graphqlUrl(): String {
-    check(context != null)
-    return "http://localhost:${context!!.webServer.port}/graphql"
+    return "http://localhost:${context.webServer.port}/graphql"
   }
 
   fun subscriptionsUrl(): String {
-    check(context != null)
-    return "http://localhost:${context!!.webServer.port}/subscriptions"
+    return "http://localhost:${context.webServer.port}/subscriptions"
   }
 
   override fun close() {
-    context?.close()
+    context.close()
   }
 }
\ No newline at end of file
diff --git a/tests/scalar-adapters/src/test/kotlin/test/CustomScalarTest.kt b/tests/scalar-adapters/src/test/kotlin/test/CustomScalarTest.kt
index 83e589b583..57ea518d87 100644
--- a/tests/scalar-adapters/src/test/kotlin/test/CustomScalarTest.kt
+++ b/tests/scalar-adapters/src/test/kotlin/test/CustomScalarTest.kt
@@ -134,6 +134,7 @@ class CustomScalarTest {
 
     val customTypeAdapter = object : Adapter<Address> {
       override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Address {
+        @Suppress("UNCHECKED_CAST")
         val map = AnyAdapter.fromJson(reader, customScalarAdapters) as Map<String, Any?>
 
         return Address(map.get("street") as String, map.get("number") as Int)
diff --git a/tests/schema-changes/src/test/kotlin/test/SchemaChanges.kt b/tests/schema-changes/src/test/kotlin/test/SchemaChanges.kt
index 057d0b895d..5aeb503541 100644
--- a/tests/schema-changes/src/test/kotlin/test/SchemaChanges.kt
+++ b/tests/schema-changes/src/test/kotlin/test/SchemaChanges.kt
@@ -14,6 +14,7 @@ class SchemaChangesTest {
   fun schemaChanges() = runTest {
     val operation = GetFieldQuery()
 
+    @Suppress("UNUSED_VARIABLE")
     val v1Data = """
       {
         "field": {
diff --git a/tests/websockets/src/commonTest/kotlin/AppSyncTest.kt b/tests/websockets/src/commonTest/kotlin/AppSyncTest.kt
index aea4c2bb02..27a98c1822 100644
--- a/tests/websockets/src/commonTest/kotlin/AppSyncTest.kt
+++ b/tests/websockets/src/commonTest/kotlin/AppSyncTest.kt
@@ -39,8 +39,10 @@ import kotlin.test.Test
 @Ignore
 class AppSyncTest {
 
+  @Suppress("UNREACHABLE_CODE")
   @Test
   fun simple() = runTest {
+    @Suppress("UNUSED_VARIABLE")
     val apiKey = TODO("changeMe")
     val host = "6l5lltvi6fgmrpx5abfxrtq6wu.appsync-api.eu-west-3.amazonaws.com"