I have a Kotlin project where I'd like to have Kotlin warnings treated as errors. How can I do that?
You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).
Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler. Update Language version and Api version to the one you wish. This should be the accepted answer.
Yes, when targeting the JVM, Kotlin is compiled to JVM *. class files, which is a bytecode format that can later be either interpreted by a JVM, or compiled to the machine code by the JVM during the program run (JIT), or even compiled ahead-of-time (AOT) down to the machine code.
Since Kotlin 1.2, the command line argument -Werror
is supported. In Gradle, it's named allWarningsAsErrors
:
compileKotlin { kotlinOptions.allWarningsAsErrors = true }
This does not appear to be currently available in the Kotlin command-line help, or arguments available to the Kotlin compiler:
K2JVMCompilerArguments.java
and
CommonCompilerArguments.java
But some people in Gradle do things like this to scan logging of the compiler to know when a warning was generated. How to fail gradle build on Javadoc warnings
Within the IDE Plugins available for Kotlin (Intellij IDEA and Eclipse) there is no such option.
You should file a feature request (or check if one already exists) in YouTrack which has all the issue tracking for the Kotlin project. And if you do so, please post the issue here so it can be tracked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With