在Maven模块化项目中查找未使用的代码 [英] Find unused code in a Maven modularised project

查看:85
本文介绍了在Maven模块化项目中查找未使用的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to clean up an old project and general knowledge here is that the project contains lots of unused code that we could remove. That would save some headaches and make maintenance easier.

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

I found the Eclipse Core Tools plugin which looks like a great tool, but in our case we have a Maven2 project that is split in 3 modules. I can't seem to be able to run the "find unreferenced members" on the parent project, and 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...

有人克服了这个问题吗?还是找到了解决此问题的另一种方法?

Anyone has overcome that issue? Or found another way to go about this?

谢谢.

推荐答案

当我在其中一个模块上运行它时,它会完全忽略其他模块可能正在使用某些公共成员的事实……

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在

Yes, that's the problem, and that's why there is no real deterministic way to do find unused code as reminded by @cletus in this previous answer.

话虽如此,诸如PMD(及其 unusedcode 规则)之类的工具,<无论如何,a href ="http://findbugs.sourceforge.net/" rel ="nofollow noreferrer">查找错误可能会帮助.像 IntelliJ 这样的IDE(Java代码检查在Community Edition中完全可用)和Eclipse也对此提供了良好的支持.

Having that said, tools like PMD (and its unusedcode rule), Findbugs may help anyway. IDEs like IntelliJ (Java code inspections are fully available in the Community Edition) and Eclipse also have good support for this.

对于IntelliJ,请查看全局未使用的声明检查:

For IntelliJ, have a look at Global unused declaration inspection:

由于Intellij IDEA代码洞察引擎背后的内部索引有所改进,Maia能够立即突出显示整个项目中未使用的一些Java类,方法和字段.

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 插件:

For Eclipse, there is the UCDetector plugin:

UCDetector(必需代码检测器)是一个开源eclipse插件工具,用于查找不必要的(死)公共Java代码.它还尝试使代码成为最终的,受保护的或私有的.

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.

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

But I confess that I'm not sure if any of these solution will really work across modules. In that case, my suggestion would be to put all the code in one "janitor" project (yeah, this is ugly but well...) and to run the tools on it (and to clean modules based on the obtained results).

这篇关于在Maven模块化项目中查找未使用的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆