我想这样做,以便我可以使用intellij 14.x运行PMD检查作为外部工具
根据pmd 4.x,我能找到的唯一文档是旧的和过时的。 我如何让它正常工作? 是否有人使用PMD作为外部工具? 我尝试下载内置的PMD插件,但是当我将它指向我的custom_pmd_ruleset.xml时,它完全忽略了它 - >也许插件坏了。
I would like to make it so that I can Run a PMD check as an external tool from withing intellij 14.x
The only documentation I can find is old and outdated based on pmd 4.x. How do I get it working correctly? Is anyone out there using PMD as an external Tool? I tried downloading the built in PMD plugin but when I pointed it to my custom_pmd_ruleset.xml it ignored it entirely --> perhaps the plugin is broken.
最满意答案
命令行解析器在PMD 5.0.1中已更改,但遗憾的是文档从未更新过。 这些是变化:
args[0]现在是-dir args[1]现在是-format args[2]现在是-rulesets当你-format ideaj ,它还需要三个参数。 现在使用-property {name}={value}指定那些报告格式特定参数:
args[3]现在是-property sourcePath args[4]现在是-property classAndMethodName args[5]现在是-property singleFileNamePMD 4文档中给出的示例命令行使用了以下参数:
"$FilePath$" # args[0] ideaj # args[1] unusedcode,imports # args[2] "$Sourcepath$" # args[3] $FileClass$.method # args[4] $FileName$ # args[5]请注意,第4个参数在文档中实际上是错误的, $FileClass.method应该是$FileClass$.method 。
所以在PMD 5中,这是:
pmd \ -dir "$FilePath$" \ -format ideaj \ -rulesets "unusedcode,imports" \ -property sourcePath="$Sourcepath$" \ -property classAndMethodName="$FileClass$.method" \ -property singleFileName="$FileName$您可以像这样配置IntelliJ:
文件>设置 工具>外部工具 添加新的外部工具: 名称:PMD(或任何你喜欢的) 描述:PMD源代码分析器(或任何你喜欢的) 选项:执行后同步文件; 打开控制台 显示:主菜单; 编辑菜单; 项目意见; 搜索结果 程序: path/to/pmd-bin-5.8.1/bin/run.sh 参数: pmd -dir "$FilePath$" -format ideaj -rulesets "unusedcode,imports" -property sourcePath="$Sourcepath$" -property classAndMethodName="$FileClass$.method" -property singleFileName="$FileName$ 工作目录: $ProjectFileDir$After a fair bit of research, here's what worked for me:
And here's the classpath part that's super long and cut off in the image:
-cp "C:\Users\nate\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\nate\.m2\repository\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar;C:\Users\nate\.m2\repository\net\sourceforge\pmd\pmd-core\5.3.2\pmd-core-5.3.2.jar;C:\Users\nate\.m2\repository\net\sourceforge\pmd\pmd-java\5.3.2\pmd-java-5.3.2.jar;C:\Users\nate\.m2\repository\asm\asm\3.1\asm-3.1.jar;C:\Users\nate\.m2\repository\jaxen\jaxen\1.1.1\jaxen-1.1.1.jar;C:\Users\nate\.m2\repository\com\beust\jcommander\1.48\jcommander-1.48.jar" net.sourceforge.pmd.PMD -R "$ModuleFileDir$\src\test\resources\custom-pmd-rules.xml" -d "$FileDirRelativeToProjectRoot$/$FileName$"Hopefully that saves someone some time getting it working. Enjoy.
更多推荐
发布评论