Intellij idea PMD作为外部工具在intellij内部工作

Intellij idea PMD作为外部工具在intellij内部工作,intellij-idea,pmd,Intellij Idea,Pmd,我想这样做,我可以运行一个PMD检查作为一个外部工具从与intellij 14.x 我能找到的唯一文档是基于pmd 4.x的旧文档和过时文档。如何使其正常工作?是否有人使用PMD作为外部工具?我尝试下载内置PMD插件,但当我将其指向我的自定义_PMD_ruleset.xml时,它完全忽略了它-->可能插件已损坏。经过一番研究,以下是对我有效的方法: 下面是类路径部分,它超长,在图中被截断: -cp "C:\Users\nate\.m2\repository\commons-io\commons

我想这样做,我可以运行一个PMD检查作为一个外部工具从与intellij 14.x


我能找到的唯一文档是基于pmd 4.x的旧文档和过时文档。如何使其正常工作?是否有人使用PMD作为外部工具?我尝试下载内置PMD插件,但当我将其指向我的自定义_PMD_ruleset.xml时,它完全忽略了它-->可能插件已损坏。

经过一番研究,以下是对我有效的方法:

下面是类路径部分,它超长,在图中被截断:

-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$"

希望这能节省一些时间让它工作。享受。

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 singleFileName
所用参数中给出的示例命令行:

"$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-规则集“unusedcode,imports”-属性sourcePath=“$sourcePath$”-属性classAndMethodName=“$FileClass$.method”-属性singleFileName=“$FileName$”
    • 工作目录:
      $ProjectFileDir$