3

We just added the PMD plugin to our Gradle build and it works just fine on on my developer computer but fails on our build server which is Bamboo.
The error message is

  • What went wrong:
    Execution failed for task ':pmdMain'.
    java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

Gradle version and Java version are the same on both machines - "Gradle 2.7" and "1.8.0_60 (Oracle Corporation 25.60-b23)".

I've seen that some people had problems with a xml-apis-dependency but when I run "gradle dependencies" on my local machine there is no xml-apis-dependency.

Edit: Even though it "felt wrong", I've tried adding a dependency to xml-apis but with the same result.

Any ideas?

Regards Peter

Peter Westlin
  • 121
  • 2
  • 6
  • check this link:http://stackoverflow.com/questions/10234201/appengine-error-java-lang-noclassdeffounderror-org-w3c-dom-elementtraversal – soorapadman Oct 26 '15 at 06:07
  • Thanks for answering! Before I posted my question I tried adding xml-apis as a dependency but the outcome is the same. It does not feel right to add xml-apis as a dependecy because it works on my local machine without it. – Peter Westlin Oct 26 '15 at 06:25

1 Answers1

3

This might be due the xerxes version, PMD is using, which transitively depends on xml-apis. While Gradle and Java versions are the same, the filesystem might be different and the classpath ordering might therefore be different - e.g. a different xml-apis jar file could hide the other.

By default, gradle uses PMD 5.2.3.

However, with PMD 5.3.0, two things changed:

  • PMD has been modularized - which means, that the gradle plugin uses now just the dependencies of pmd-java and doesn't need the dependencies of all supported languages.
  • The xerces dependency has been dropped and only the default java XML APIs are used.

So, settings the toolVersion to 5.3.5 or even 5.4.0 should avoid this problem.

pmd {
  toolVersion = "5.3.5"
  ...
}
adangel
  • 1,816
  • 14
  • 17