Home > front end >  Is there a way in Gradle to generate an error when Experimental Kotlin features are found to be in u
Is there a way in Gradle to generate an error when Experimental Kotlin features are found to be in u

Time:12-10

Simply, we are very sensitive to ABI changes, and we want to prevent people on our team using experimental features because of issues this can cause at runtime. Is there a way either via gradle configuration and/or a custom gradle plugin to detect when such features are used and elicit a compiler warning, preferably with a custom error message?

CodePudding user response:

The Kotlin compiler (and transitively Gradle) will warn you by default (or even show an error) when experimental features are used.

To change this behaviour, the developer has to opt in via an @OptIn annotation or -opt-in compiler argument. If you're trying to avoid accidental usages of experimental features, this should therefore be sufficient (if we consider that opting in to an experimental feature is not an accident).

If you want to prevent usages of @OptIn itself, this is a different story. Technically @OptIn itself is still experimental at the moment, so there will be a warning for usages of it anyway unless someone adds the compiler argument to opt in to the @OptIn experimental annotation :) So currently just having a culture of not modifying compiler arguments should be enough, but that of course will change once @OptIn gets stable.

I am not aware of plugins that already do this, but you should be able to write a plugin with Kotlin Symbol Processing that checks for those annotations (never tried it myself, though).

As a side note about ABI compatibility, there is also the binary-compatibility-validator, but that's for your own code, so I don't think it's related to the question.

  • Related