How could I pass compiler args in a multiplatform ...
# gradle
l
How could I pass compiler args in a multiplatform repository? e.g. on my root `build.gradle`:
Copy code
allprojects {
  tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile).configureEach { task ->
    task.kotlinOptions {
    }
  }
}
but this errors with
Copy code
Execution failed for task ':mymodule:runCommonizer'.
> Could not create task ':mymodule:compileKotlinIosArm64'.
   > Cannot query the value of task ':mymodule:compileKotlinIosArm64' property 'compilation' because it has no value available.
note
mymodule
has the
multiplatform
plugin applied
b
Try exact same thing in afterEvaluate { } block
l
the error changed, good sign I guess, now i get:
Copy code
> Could not create task ':store:compileDebugKotlinAndroid'.
   > Project#afterEvaluate(Closure) on project ':store' cannot be executed in the current context.
note, i added as:
Copy code
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile).configureEach { task ->
    afterEvaluate {
      task.kotlinOptions {
      }
    }
  }
b
Ah, afterEvaluate needs to wrap your tasks invocation
Basically top level
l
oh, I get the same error as before (the first one), with
Copy code
afterEvaluate {
    tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile).configureEach { task ->
      task.kotlinOptions {
      }
    }
  }
No, apologies. It’s similar, but in a different task:
Copy code
Cannot query the value of task ':mymodule:compileIosMainKotlinMetadata' property 'compilation' because it has no value available.
b
How about this:
Copy code
allprojects {
  afterEvaluate {
    tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile> { // this == task
      kotlinOptions {
      }
    }
  }
}
If that doesn;t work you can try swapping the order of allprojects and afterEvaluate
l
No dice. But I changed the
<
and
>
to parenthesis because I’m editing a .groovy file, not kotlin. But still, same error 😞
so basically
Copy code
allprojects {
  afterEvaluate {
      tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile) { // this == task
          kotlinOptions {
          }
      }
  }
}
b
Hmm, then I'd suggest you writing the logic you want to reuse in buildSrc and apply it to each module individually
allprojects can often be flaky due to script resolution dependencies, unfortunately
You might also try using .kts gradle scripts. But that's just a wild guess with no guarantees to work.
l
Oh I figured 🤦 it seems I was using an old task, the right one is
tasks.KotlinCompile
instead of
dsl.KotlinCompile
🎉 1
b
can you post your final solution here for future explorers?
l
absolutely. that would be:
Copy code
allprojects {
  tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { task ->
    task.kotlinOptions {
    }
  }
}