I'm working on a new codebase and migrating the system to a new framework.
There are a number of packages that I would like to deprecate, just to make it very clear to other developers that everything inside this package should not be used anymore for new development.
What is the best way to indicate that an entire package has been deprecated?
Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future. The need for deprecation comes about because as a class evolves, its API changes.
You can still use deprecated code without performance being changed, but the whole point of deprecating a method/class is to let users know there's now a better way of using it, and that in a future release the deprecated code is likely to be removed.
How to Deprecate? We use the @Deprecated annotation to deprecate a method, class, or field, and the @deprecated Javadoc tag in the comment section to inform the developer about the reason for deprecation and what can be used in its place.
I had to do this recently and used the package-info.java
file to deprecate the package.
http://www.intertech.com/Blog/whats-package-info-java-for/
Add a package-info.java
file to your package with only the package declaration:
/** * @deprecated As of release 2.0, replaced by {@link com.acme.new.package} */ @Deprecated package com.acme.old.package;
In Eclipse, all places where the user imports a class from this package will be underlined with a deprecation warning.
You said it yourself: You want to deprecate everything that's inside a package, not the package itself. The package is nothing but a namespace and deprecating a namespace would have a different meaning - like don't use this namespace anymore. Like don't add any new items to that namespace.
In your case, I suggest you deprecate each public method (and field) of each class that shouldn't be used anymore. This becomes visible in modern IDE's and developers are warned when they want to use the old classes and methods. And you can look through your code and refactor it step by step to eliminate dependencies of those classes and methods.
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