我在一个单独的jenkins构建中使用maven运行pmd
/tools/apache-maven-3.0.4/bin/mvn pmd:pmd --settings $Settings > /logfiles/pmdResults.$Job 2>&1
结果xml格式不正确。对于某些违规行为,它没有违规的结束标记。因此jenkins无法解析xml。
实例XML
<file name="/home/bhebbar/TestProj/src/main/java/com/hebbar/MyClass.java">
<violation beginline="20" endline="20" begincolumn="1" endcolumn="22" rule="UnusedImports" ruleset="Best Practices" package="com.hebbar" class="MyClass" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_bestpractices.html#unusedimports" priority="4">
Avoid unused imports such as 'osmdb.common'
</violation>
<violation beginline="21" endline="21" begincolumn="1" endcolumn="35" rule="UnusedImports" ruleset="Best Practices" package="com.hebbar" class="MyClass" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_bestpractices.html#unusedimports" priority="4">
Avoid unused imports such as 'com.sort.filtersort'
</violation>
<violation beginline="50" endline="55" begincolumn="12" endcolumn="56" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getTProfiles" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="68" endline="68" begincolumn="12" endcolumn="76" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getTProfile" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="83" endline="88" begincolumn="12" endcolumn="56" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getAProfiles" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="101" endline="101" begincolumn="12" endcolumn="78" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getAProfile" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="103" endline="106" begincolumn="12" endcolumn="64" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getCProfileName" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="108" endline="112" begincolumn="12" endcolumn="57" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getCProfileDetails" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="114" endline="116" begincolumn="12" endcolumn="59" rule="UnnecessaryModifier" ruleset="Code Style" package="com.hebbar" class="MyClass" method="getCProfileDetails" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_codestyle.html#unnecessarymodifier" priority="3">
<violation beginline="119" endline="119" begincolumn="2" endcolumn="2" rule="EmptyStatementNotInLoop" ruleset="Error Prone" package="com.hebbar" class="MyClass" externalInfoUrl="https://pmd.github.io/pmd-6.0.1/pmd_rules_java_errorprone.html#emptystatementnotinloop" priority="3">
An empty statement (semicolon) not part of a loop
</violation>
</file>
我收到了以下错误
pmd.xml failed due to an exception:
org.xml.sax.SAXParseException: The element type "violation" must be terminated by the matching end-tag "</violation>".
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.commons.digester3.Digester.parse(Digester.java:1642)
at org.apache.commons.digester3.Digester.parse(Digester.java:1701)
at hudson.plugins.pmd.parser.PmdParser.parse(PmdParser.java:70)
at hudson.plugins.analysis.core.AbstractAnnotationParser.parse(AbstractAnnotationParser.java:53)
at hudson.plugins.analysis.core.FilesParser.parseFile(FilesParser.java:323)
at hudson.plugins.analysis.core.FilesParser.parseFiles(FilesParser.java:281)
at hudson.plugins.analysis.core.FilesParser.parserCollectionOfFiles(FilesParser.java:232)
at hudson.plugins.analysis.core.FilesParser.invoke(FilesParser.java:201)
at hudson.plugins.analysis.core.FilesParser.invoke(FilesParser.java:31)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2484)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:328)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
请你帮我理解在运行pmd时是否需要设置一些标志?如何才能让jenkins正确解析?