Hey folks :wave: Working on a library and a new m...
# library-development
o
Hey folks 👋 Working on a library and a new major version is coming up. I'm deprecating a bunch of things with
@Deprecated
, but this obviously gives warnings on all usages of the given classes. The aim is to warn users to not use these classes, but internally I have to keep support for them. Is there a way to suppress deprecation warnings of my own code without suppressing deprecations from let's say other libraries etc?
âž• 1
d
@Suppress("DEPRECATION")
or
@Suppress("DEPRECATION_ERROR")
, depending on the
DeprecationLevel
.
m
That works the same for all declarations.
So if you suppress it in a file (imports are specifically problematic) you lose the ability to detect all the other deprecations
d
Ah, got it. Sorry, I misread the question.
m
I've been wondering about this too for a while but never really formalized the question
We have
@file:Suppress("DEPRECATION")
in a bunch of files because we still need to use those symbols internally but the end result is that we effectgivelly ignore all deprecations in those files
https://youtrack.jetbrains.com/issue/KT-30155/Allow-to-suppress-DEPRECATION-for-single-import would help a lot already as we could be a lor more focused about the suppressions
d
No, I don't think there's anything in the language that can help with that. We are just `Suppress`ing everything in our libraries. The only viable option today is to restructure the code to, say, only refer to these entities in isolated places.
As for imports: are there any downsides to using star imports for first-party packages?
b
instead of * imports you can use fully qualified names (but yeah, not cool either)
o
Being able to suppress imports would be a great thing already, but it would still require quite some manual effort to suppress everything. Just thinking out loud: scoping deprecations would solve all of these issues at once. Somehow you would specify this deprecation is only to warn outside of your library and that would be all. Kinda like Android's RestrictTo.Scope, but inverted I guess
âž• 1
m
are there any downsides to using star imports for first-party packages?
Mainly that it requires special formatting rules if not the star imports end up being removed I think. Have never really dug into this but I've seen it before
o
Thanks for all the swift replies btw! For now I think I will suppress as much as possible without suppressing whole files
m
I'd be happy with a compiler argument:
-Xignore-deprecation-for=com.example1,comp.example2,...
Feels very specific but maybe that'd do it?
o
That would also do the trick âž•