Here's a question that suggests using dependency:analyze
to remove the unused dependencies in a project. But when I read through the sonatype document on this, I came to understand that I may have to be careful if I were to delete those unused dependencies.
Here's the relevant part:
Be careful when removing any unused, declared dependencies unless you have very good test coverage, or you might introduce a runtime error. A more sinister issue pops up with bytecode optimization. For example, it is legal for a compiler to substitute the value of a constant and optimize away the reference. Removing this dependency will cause the compile to fail, yet the tool shows it as unused. Future versions of the Maven Dependency plugin will provide better techniques for detecting and/or ignoring these types of issues.
I don't seem to understand this scenario, are they talking about the scenario where if any of the dependency's classes/methods were accessed through reflection API? If so, does maven-3's dependency plugin have a better technique of handling this?
Also why isn't there a
unused + undeclared
dependency analysis? A transitive dependency that I have(undeclared) can be unused but still be part of my 'war', which I'll prefer to exclude, correct?
EDIT: I guess the note mentioned on dependency scopes would answer my second question.