Gradle with PMD - NoClassDefFoundError

I have many OSGI bundles with BND tool. I am using PMD for code analysis with my custom rule.

settings.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.1'
    }
}
apply plugin: 'biz.aQute.bnd.workspace'

build.gradle

subprojects {
	apply plugin: 'pmd'
	apply plugin: 'maven-publish'
	buildscript {
		repositories {
			mavenCentral()
			mavenLocal()
		}

		def bndPlugin = files(configurations.classpath.files)
	}

	pmd {
		consoleOutput = true
		toolVersion = "6.27.0"
		reportsDir = file("pmd/reports")
		ruleSets = ["${sbDir}/build/pmd/rules/Sample.xml"]
		ignoreFailures = true
		sourceSets = [sourceSets.main]
	}
}


tasks.withType(Pmd) {
	classpath = bndPlugin
}

I have only a single build.gradle which is located under ‘projects’ directory. There is no build.gradle in each bundle directory.

projects

  • bundle1
  • bundle2
  • bundle3
    .
    .
    .

When I run ‘build’, it works. It compiles/generates jar under ‘generated’ directory, but when i run ‘gradle check’ or ‘gradle pmdMain’, I get many ‘java.lang.NoClassDefFoundError (from several bundles)’ which points to one of the classes in the common bundles. The only solution is to create a build.gradle, define the bundle dependency in the build.gradle and put it in the bundle (which throws NoClassDefFoundError’ directory), but I want to resolve this in the main build.gradle file instead of creating build.gradle per bundle.

I ran ‘publishToMavenLocal’, so all the bundles exist in the local maven central repository. I confirmed it.

Somehow It seems PMD is unable to resolve the type by throwing 'Caused by: java.lang.ClassNotFoundException: '.

I tried to reproduce it with some simple sample bundles, but i can’t.

Is there anything wrong with my gradle file or PMD configuration?