Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the Kotlin compiler treat warnings as errors?

Tags:

kotlin

I have a Kotlin project where I'd like to have Kotlin warnings treated as errors. How can I do that?

like image 768
Jeffrey Charles Avatar asked Jan 02 '16 03:01

Jeffrey Charles


People also ask

How do I compile without warnings?

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).

How do I change my Kotlin compiler version?

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.

How is Kotlin code compiled?

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.


2 Answers

Since Kotlin 1.2, the command line argument -Werror is supported. In Gradle, it's named allWarningsAsErrors:

compileKotlin {     kotlinOptions.allWarningsAsErrors = true } 
like image 81
Alexander Udalov Avatar answered Oct 13 '22 23:10

Alexander Udalov


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.

like image 23
4 revs, 2 users 98% Avatar answered Oct 14 '22 00:10

4 revs, 2 users 98%