2013-01-04 114 views
0

我已經配置maven pmd插件到一個maven父級pom中,我使用了一個名爲MFactors3的測試項目。當我在Eclipse中使用m2Eclipse構建這個小型項目時,PMD報告了大量的違規行爲。當我從命令行生成相同的項目時,PMD會在目標/站點文件夾中生成一個空的違規文件。maven 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 

回答

1

我會回答我自己的問題。基本上是用戶錯誤,我從父pom中刪除了一段maven-pmd-plugin配置代碼。我這樣做是因爲該示例取自文檔,顯示正在使用的自定義規則集。我想要默認的規則集。

我花了很長時間才意識到我的錯誤,因爲插件運行時沒有任何規則集,也沒有指出任何問題(至少應該警告說沒有規則集正在使用中?)。

這裏需要的是正確的配置元素:

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

我也想指出的是,這些規則集被嵌入在插件的jar文件。你不會在任何地方的文件系統上找到它們。