Hi, I'm trying to automatically add compiler opt-i...
# gradle
j
Hi, I'm trying to automatically add compiler opt-ins for all my modules (where it matters). But the "where it matters" is important, otherwise when the opt-in annotation is not available the build fails (as we utilize warning as errors). Zac's workaround is nice, but doesn't account for transitive dependency.
Copy code
configurations
    .configureEach {
      incoming.afterResolve {
        dependencies.forEach { dependency ->
          if (dependency.name == "eithernet") {
            tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
              kotlinOptions {
                @Suppress("SuspiciousCollectionReassignment")
                freeCompilerArgs += "-Xopt-in=com.slack.eithernet.ExperimentalEitherNetApi"
              }
            }
          }
        }
      }
    }
I've spent two days resolving the transitive deps but still failing to do it properly anyhow. Any idea?
v
I guess instead of
dependencies.forEach
which only gives you the declared dependencies you need the resolution result, so something like
resolutionResult.allDependencies
.
👍 1