workflow-kotlin icon indicating copy to clipboard operation
workflow-kotlin copied to clipboard

Add Gradle logic to validate RequiresOptIn annotation dependencies and automatically opt-in our own code

Open zach-klippenstein opened this issue 4 years ago • 1 comments
trafficstars

Turns out that if you have RequiresOptIn annotations in a module and you depend on that module to annotate some code, the compiler will only validate opt-ins if the dependency on the annotations module is specified as apicompileOnly and implementation will cause the IDE to redline, but not the command line build, for some reason.

I recently wrote a plugin on an internal project (https://github.com/squareup/market/pull/1346) that validates this, as well as automatically adds the -Xopt-in= compiler flag to modules that use such annotations so you don't have to write @OptIn() on all your own code. We could either copy that, or we could open-source it and use it here.

I also filed an issue to generally move our custom logic to Gradle plugins as #406.

zach-klippenstein avatar Apr 13 '21 16:04 zach-klippenstein

Filed issues to Kotlin for these:

  • annotation classpath requirement: https://youtrack.jetbrains.com/issue/KT-46064
  • api dependency requirement: https://youtrack.jetbrains.com/issue/KT-46065

zach-klippenstein avatar Apr 13 '21 17:04 zach-klippenstein