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?
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.
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:In Eclipse, all places where the user imports a class from this package will be underlined with a deprecation warning.
Use AspectJ. Create an Aspect that issues a compiler warning when the package is used:
(You can easily add AspectJ to your build if you use ant or maven)
For those who came later...
My solution with IDEA "Replace in Path"
Text to find: (public|protected)+(\s)(abstract)(\s)(static)(\s)(final)(\s)*(class|interface|enum|Enum)
Replace with: @Deprecated\n\$1 \$3 \$5 \$7 \$9
Options: (select) Regular expressions
Directory: {Choose dir}
You can create Package annotation and deprecate any package with
@Deprecated
:)