Is it possible to use Xsuppress-warnings for depre...
# getting-started
j
Is it possible to use Xsuppress-warnings for deprecation in Kotlin? I tried follow https://youtrack.jetbrains.com/issue/KT-8087 but when used it, Kotlin compiler says flag not supported. My main goal is I want have warningsAsErrors but ignore deprecation error. I want the warning in IDE but allow compiler continue. Or do I need to skip strict warning as errors? Or if possible change level of deprecation to information instead of warning?
d
-Xsuppress-warning
is supported starting since 2.1.0, which is not released yet You can try out pre-release version
2.1.0-RC
which is published
j
Oh ok and I cant enable Kotlin compiler version 2.1 without actually using Kotlin 2.1? Somewhere read need experimental flags on? Also do you know if this will continue strike through code in IDE but just omit compiler warning to allow compile? I still want deprecation warnings, just not fail compile 😁
d
Yes, it's about the compiler version, not language version
Also do you know if this will continue strike through code in IDE but just omit compiler warning to allow compile?
No, it won't. This flag is equivalent of adding
@file:Suppress(...)
to each file in your project And IDE highlighting for deprecated declarations take into account warnings/errors from the compiler
j
So you saying it will just suppress warning and ignore. Crap. You dont know if Kotlin will support information as deprecation level? Only warning, error or hidden. Any recommendations? I want prevent using depeecated things in third party library but not in my own code 😁 I guess I cant have it all. Any recommendations how to deal with this? Mark my legacy depeecated code as experimental or opt in to get info?
d
Does your own code located into the same project as the deprecated library code? If yes, then it's completely fine to suppress the warning globally, as when you start to delete/modify the code the IDE will find all usages of it If no, then your code doesn't differ much from 3rd-party code
j
Uhm it depends. Currently not allow any code use depeecated code so cant do. But I guess could be same module. Ideally want suppress treat deprecations as errors but only my own code, if someone else then mark as error. Suppression just makes the deprecation useless to help developers get informed stop using this code. Today using TODO comments ..
d
Unfortunately, there is no silver bullet • don't update existing production code • treat warnings as errors • warn about deprecations in your production code Pick two
Me personally prefer to update all usages of something which became deprecated immediately or suppress deprecation warning in some specific places which cannot be currently migrated But applicability of this approach depends on the scale of course
j
I just want something have light deprecation. In my case design system components I want to do phased migration depeecated old component and add replace with tell use this. If suppress it will superseed and cause no value. Not sure, just lack tools of doing phased migrations between developers.