java - 在 Maven 模块化项目中查找未使用的代码

标签 java maven-2 module

我必须清理一个旧项目,这里的常识是该项目包含许多我们可以删除的未使用代码。这将减少一些麻烦并使维护更容易。

我找到了 Eclipse Core Tools 插件,它看起来是一个很棒的工具,但在我们的例子中,我们有一个 Maven2 项目,该项目分为 3 个模块。 我似乎无法在父项目上运行“查找未引用的成员”,当我在其中一个模块上运行它时,它完全忽略了其他模块可能正在使用一些公共(public)成员的事实......

有人解决过这个问题吗?或者找到另一种方法来解决这个问题?

谢谢。

最佳答案

when I run it on one of the modules it ignores completely the fact that other modules might be using some of the public members...

是的,这就是问题所在,这就是为什么没有真正确定性的方法来查找未使用的代码,正如@cletus 在this previous answer 中所提醒的那样.

话虽如此,PMD(及其 unusedcode 规则)、Findbugs 等工具无论如何都可以帮助。类似 IntelliJ 的 IDE (Java 代码检查在社区版中完全可用)并且 Eclipse 对此也有很好的支持。

对于 IntelliJ,请查看 Global unused declaration inspection :

Thanks to improvements in the internal indexes behind the Intellij IDEA code insight engine, Maia will be able to instantly highlight some java classes, methods and fields which are unused across the entire project.

对于 Eclipse,有 UCDetector插件:

UCDetector (Unecessary Code Detector) is an Open Source eclipse PlugIn Tool to find unecessary (dead) public java code. It also tries to make code final, protected or private.

alt text

但我承认我不确定这些解决方案中的任何一个是否真的可以跨模块工作。在那种情况下,我的建议是将所有代码放在一个“看门人”项目中(是的,这很丑陋但很好......)并在其上运行工具(并根据获得的结果清理模块)。

关于java - 在 Maven 模块化项目中查找未使用的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2245922/

相关文章:

python tidylib模块错误

module - Ansible playbook 阻止所有 IP 排除一个或多个 IP

javascript - 如何创建并依赖异步 JavaScript 模块?

java - 在循环中使用 java "for each"和 "continue"

java - AR核心 : what is the min SDK version supported ?

java - 使 java.util.Properties 的 load 和 getproeprty 方法线程安全

maven-2 - Maven 版本 :prepare overwrites SCM properties with resolved values

java - acm.graphics 库 - 小程序启动

java - 在maven中从开发发布到生产

maven - 如何从命令行获取属性值,如果不是从环境中获取,如果不是 - 默认值?