0

我已将 maven pmd 插件配置为一个 maven 父 pom,我将其与一个名为 MFactors3 的测试项目一起使用。当我在 Eclipse 中使用 m2Eclipse 构建这个小项目时,PMD 报告了很多违规行为。当我从命令行构建相同的项目时,PMD 在目标/站点文件夹中生成一个空的违规文件。

我的父 pom 有部分直接取自推荐的 maven pmd 文档。我现在没有显示任何 pom 材料,因为插件正在被调用并且它运行成功。

下面是从命令行运行 'mvn pmd:pmd -X' 的输出。配置数据看起来完全正确。但未检测到任何违规行为。为什么?

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-pmd-plugin:2.7.1:pmd' with basic configurator -->
[DEBUG]   (f) aggregate = false
[DEBUG]   (f) compileSourceRoots = [/Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30 /src/main/java]
[DEBUG]   (f) excludeRoots = [/Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/generated-sources/stubs]
[DEBUG]   (f) excludes = [**/*Bean.java, **/generated/*.java]
[DEBUG]   (f) format = xml
[DEBUG]   (f) includeTests = false
[DEBUG]   (f) linkXRef = true
[DEBUG]   (f) minimumPriority = 5
[DEBUG]   (f) outputDirectory = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/site
[DEBUG]   (f) project = MavenProject: edu.psu.sweng497a:MFactors30:0.0.1-SNAPSHOT @ /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: edu.psu.sweng497a:MFactors30:0.0.1-SNAPSHOT @ /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/pom.xml]
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceEncoding = utf-8
[DEBUG]   (f) targetDirectory = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target
[DEBUG]   (f) targetJdk = 1.6
[DEBUG]   (f) testSourceRoots = [/Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/src/test/java]
[DEBUG]   (f) xrefLocation = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/site/xref
[DEBUG]   (f) xrefTestLocation = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/site/xref-test
[DEBUG] -- end configuration --
[DEBUG] Preparing ruleset: rulesets/basic.xml
[DEBUG] Before: rulesets/basic.xml After: basic.xml
[DEBUG] The resource 'rulesets/basic.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'rulesets/basic.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'rulesets/basic.xml' was found as jar:file:/Users/Robert/.m2/repository/pmd/pmd/4.3/pmd-4.3.jar!/rulesets/basic.xml.
[DEBUG] Preparing ruleset: rulesets/unusedcode.xml
[DEBUG] Before: rulesets/unusedcode.xml After: unusedcode.xml
[DEBUG] The resource 'rulesets/unusedcode.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'rulesets/unusedcode.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'rulesets/unusedcode.xml' was found as jar:file:/Users/Robert/.m2/repository/pmd/pmd/4.3/pmd-4.3.jar!/rulesets/unusedcode.xml.
[DEBUG] Preparing ruleset: rulesets/imports.xml
[DEBUG] Before: rulesets/imports.xml After: imports.xml
[DEBUG] The resource 'rulesets/imports.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'rulesets/imports.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'rulesets/imports.xml' was found as jar:file:/Users/Robert/.m2/repository/pmd/pmd/4.3/pmd-4.3.jar!/rulesets/imports.xml.
[WARNING] Unable to locate Source XRef to link to - DISABLED
[DEBUG] Exclusions: **/*~,**/#*#,**/.#*,**/%*%,**/._*,**/CVS,**/CVS/**,**/.cvsignore,**/RCS,**/RCS/**,**/SCCS,**/SCCS/**,**/vssver.scc,**/project.pj,**/.svn,**/.svn/**,**/.arch-ids,**/.arch-ids/**,**/.bzr,**/.bzr/**,**/.MySCMServerInfo,**/.DS_Store,**/.metadata,**/.metadata/**,**/.hg,**/.hg/**,**/.git,**/.git/**,**/BitKeeper,**/BitKeeper/**,**/ChangeSet,**/ChangeSet/**,**/_darcs,**/_darcs/**,**/.darcsrepo,**/.darcsrepo/**,**/-darcs-backup*,**/.darcs-temp-mail,**/*Bean.java,**/generated/*.java
[DEBUG] Inclusions: **/*.java
[DEBUG] Velocimacro : added #link(  href name target img position alt border width height ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #image(  img alt border width height ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #banner(  banner id ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #links(  links ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #breadcrumbs(  breadcrumbs ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #displayTree(  display item ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #menuItem(  item ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #mainMenu(  menus ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #copyright(  ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #publishDate(  position publishDate version ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #poweredByLogo(  poweredBy ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
4

1 回答 1

1

我会回答我自己的问题。基本上这是用户错误,因为我从父 pom.xml 中删除了一部分 maven-pmd-plugin 配置代码。我这样做是因为取自文档的示例显示了正在使用的自定义规则集。我想要默认规则集。

我花了很长时间才意识到我的错误,因为插件在没有任何规则集的情况下运行并且没有指示任何问题(不应该至少警告没有使用规则集吗?)。

这是所需的正确配置元素:

<!-- Customize rulesets here -->
<rulesets>
  <ruleset>rulesets/basic.xml</ruleset>
  <ruleset>rulesets/naming.xml</ruleset>
  <ruleset>rulesets/design.xml</ruleset>
</rulesets>

我还想指出,这些规则集嵌入在插件 jar 文件中。您不会在任何地方的文件系统上找到它们。

于 2013-01-07T13:15:08.027 回答