Getting NoClassDefFoundError while running PMD task from Gradle

I am getting ‘NoClassDefFoundError’ while running PMD task via Gradle 2.0 .

I am having ‘pmd-5.1.1.jar’, ‘commons-io-1.4.jar’ as well as all the other ‘jars’ in ‘WebContent/WEB-INF/lib’ directory. My java files are in the directory ‘src\com\company\project’

Gradle Build file

apply plugin: ‘java’

apply plugin: ‘war’

apply plugin: ‘pmd’ = [‘src’]

webAppDirName = ‘WebContent’

repositories {

flatDir { dirs “WebContent/WEB-INF/lib” }


dependencies {

providedCompile fileTree(dir: “WebContent/WEB-INF/lib”, include: ‘*.jar’)


war {

archiveName “ROOT.war”


Error Log

C:\MyWorkspace\MyProject>gradle build

:compileJava UP-TO-DATE

:processResources UP-TO-DATE

:classes UP-TO-DATE


:assemble UP-TO-DATE

:pmdMain FAILED

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:pmdMain’.

java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug

option to get more log output.


Total time: 5.275 secs

This is the first time I am trying Gradle. I am able to build as well as generate WAR but PMD is failing me. Can someone please tell me what am I doing wrong? Thanks in advance :slight_smile:

The easiest way is to resolve pmd and all it’s transitive dependencies from a remote repo like Maven Central. Why do you prefer to use a lib directory instead of Maven Central? The following is an example

apply plugin: ‘pmd’

repositories {



pmd.toolVersion = “5.1.1”

This way you will get the right version of all the necessary libraries downloaded for you.

And btw, from what I can see pmd 5.1.1 requires commons-io 2.2, not 1.4.

Thanks a lot. This helps :slight_smile: