gradle 1.2:
when I use pmd plugin and type gradle check I get the following error
Execution failed for task ‘:pmdMain’. > java.lang.NoClassDefFoundError: org/jaxen/Navigator
gradle 1.2:
when I use pmd plugin and type gradle check I get the following error
Execution failed for task ‘:pmdMain’. > java.lang.NoClassDefFoundError: org/jaxen/Navigator
Can you please post the relevant parts of your build script (e.g. PMD setup) and the full stack trace (’-S’)? If possible, a reproducible example would also help.
Does your production code use jaxen, maybe as a transitive dependency?
yes, it appears to be a transitive dependency in our project, but why would that affect the classpath of gradle / pmd plugin?
Without more information from your side (as requested in my previous post), I won’t be able to help.
here is build script:
project-common.gradle
apply plugin: ‘eclipse’ apply plugin: ‘artifactory’
artifactory {
contextUrl = ‘http://sula10:8081/artifactory’
//The base Artifactory URL if not overridden by the publisher/resolver
publish {
defaults {
//publishArtifacts = false
mavenDescriptor = ‘test’
}
} } resolve {
repository {
repoKey = ‘libs-release’ //The Artifactory (preferably virtual) repository key to resolve from
}
username = ‘stuffdeploy’
password = ‘stuffdeploy’ } configurations {
svntask }
dependencies {
svntask ‘svn:svnkit:1.0.6’
svntask ‘svn:svntask:1.0.6’ }
ant {
tstamp {
format(property: ‘NOW’, pattern: ‘MM/dd/yyyy HH:mm:ss’, locale: ‘en,US’)
format(property: ‘latest.changeset’, pattern: ‘yyyyMMddHHmmss’, locale: ‘en,US’)
} }
ext {
cruiseinstance = ‘local’
stuff_common_version = “$System.env.stuff_common_version”
if (stuff_common_version == “null”)
{
stuff_common_version = “8.+”
}
println(“Using stuff_COMMON_VERSION = ${stuff_common_version}”) }
def prepareManifest(Task tsk) {
ant.typedef(resource: ‘com/googlecode/svntask/svntask.xml’, classpath: configurations.svntask.asPath)
ant.svn() {
info (path:".", revisionProperty:“subversionRevision”, urlProperty:“subversionUrl”)
}
ext.subversionRevision = ant.properties[‘subversionRevision’]
tsk.manifest {
attributes (
“Gradle-Version”: “${gradle.gradleVersion}”,
“Created-By”:"${System.properties[‘java.runtime.version’]} (${System.properties[‘java.vm.vendor’]})",
“Specification-Vendor”:“Company”,
“Specification-Title”: “${project.name}”,
“Specification-Version”: “Changeset: ${ant.properties[‘latest.changeset’]}”,
“Implementation-Version”: “Create ${ant.properties[‘NOW’]} ${System.properties[‘user.name’]} ${cruiseinstance}”,
“Subversion-Url”: “${ant.properties[‘subversionUrl’]}”,
“Subversion-Revision” : “${subversionRevision}”
)
} }
test {
includes = [’**/AllUnitTest’]
maxParallelForks = 6
forkEvery=10
maxHeapSize=“128m” }
task allTest(type: Test){
includes = [’**/AllTest’]
maxParallelForks = 6
forkEvery=10
maxHeapSize=“128m” }
jar.doFirst {
prepareManifest(jar) }
if (plugins.hasPlugin(‘war’)) {
war.doFirst {
prepareManifest(war)
} } --------------------------------------------------------- build.gradle //TEST-COMMON buildscript {
repositories {
maven { url ‘http://repo.jfrog.org/artifactory/gradle-plugins’ }
}
dependencies {
classpath(‘org.jfrog.buildinfo:build-info-extractor-gradle:2.0.16’)
} }
apply plugin: ‘java’
apply from: ‘…/BuildCommon/project-common.gradle’ apply plugin: ‘pmd’
version = “8.1.2” group = “com.company.stuff.TEST”
defaultTasks ‘checkProjectBuildDependencies’, ‘jar’
task checkProjectBuildDependencies << {
ant.property (name: “build.common.dir”, value: “…/BuildCommon”)
ant.available (file: ant.properties[‘build.common.dir’], property:“common.files.present”)
ant.fail(message:“Checkout the BuildCommon project to build this project”, unless:ant.properties[‘common.files.present’]) }
configurations { jarOnly }
dependencies {
compile ‘apache:jakarta-oro:2.0.8’
compile ‘acompany:arapi71:1’
compile ‘acompany:arcmn71:1’
compile ‘acompany:arrpc71:1’
compile ‘acompany:arutil71:1’
compile ‘acompany:oncrpc:1’
compile ‘commons-beanutils:commons-beanutils:1.6’
compile ‘commons-codec:commons-codec:1.3’
compile ‘commons-collections:commons-collections:3.2’
compile ‘commons-configuration:commons-configuration:1.3’
compile ‘commons-dbcp:commons-dbcp:1.4’
compile ‘commons-digester:commons-digester:1.7’
compile ‘commons-io:commons-io:1.4’
compile ‘commons-lang:commons-lang:2.4’
compile ‘commons-logging:commons-logging:1.1.1’
compile ‘commons-net:commons-net:1.4.1’
compile ‘commons-pool:commons-pool:1.5.4’
compile ‘commons-validator:commons-validator:1.3.1’
compile ‘com.google.code.gson:gson:2.1’
compile ‘javax.mail:mailapi:1.4.3’
compile ‘javax.servlet:servlet-api:2.4’
compile ‘jsnpp:jsnpp:0.3.1’
compile ‘log4j:log4j:1.2.16’
compile ‘oracle:ojdbc6:11.1.0.7.0’
compile ‘org.apache.httpcomponents:fluent-hc:4.2.1’
compile ‘org.apache.httpcomponents:httpclient:4.2.1’
compile ‘org.apache.httpcomponents:httpcore:4.2.1’
compile ‘spring:spring:2.0’
compile ‘tomcat:naming:0.8’
compile ‘xerces:xercesImpl:2.9.1’
compile ‘xml-apis:xml-apis:1.3.04’
testCompile ‘junit:junit:4.+’
testCompile ‘cglib:cglib-nodep:2.2.2’
testCompile ‘com.mockrunner:mockrunner:0.3.1’ }
task jarIncludeTest(type: JavaCompile) {
classpath = sourceSets.test.compileClasspath
includes =[’**/JunitHelper.*’]
source = ‘src/test/java’
destinationDir = sourceSets.main.output.classesDir
dependencyCacheDir = new File(‘dependency-cache’) }
jar.dependsOn ‘jarIncludeTest’
task TESTJar(type: Jar) { }
artifacts {jarOnly jar}
and here is stacktrace
C:\eclipse-workspace\SAMS-COMMON>gradle -s check Using SAMS_COMMON_VERSION = 8.+ :pmdMain FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ‘:pmdMain’. > java.lang.NoClassDefFoundError: org/jaxen/Navigator
Try: Run with --info or --debug option to get more log output.
Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':pmdMain '.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:68)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec uter.execute(PostExecutionAnalysisTaskExecuter.java:34)
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter $1.run(CacheLockHandlingTaskExecuter.java:34)
at org.gradle.cache.internal.DefaultCacheAccess$3.create(DefaultCacheAcc ess.java:243)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def aultCacheAccess.java:188)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def aultCacheAccess.java:241)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning Operation(DefaultPersistentDirectoryStore.java:137)
at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache Access.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter .execute(CacheLockHandlingTaskExecuter.java:32)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec ute(SkipUpToDateTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut e(ValidatingTaskExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu ter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter .execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut e(SkipOnlyIfTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter .execute(ExecuteAtMostOnceTaskExecuter.java:42)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur e(AbstractTask.java:247)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(De faultTaskPlanExecutor.java:52)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(De faultTaskPlanExecutor.java:38)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul tTaskPlanExecutor.java:30)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau ltTaskGraphExecuter.java:83)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask ExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec uter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu ter.java:67)
at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe cuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAcc ess.java:118)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc ess.java:133)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc ess.java:116)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(De faultPersistentDirectoryStore.java:129)
at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache Access.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe cuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec uter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu ter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx ecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default GradleLauncher.java:158)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle Launcher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun cher.java:81)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav a:38)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execut e(InProcessGradleLauncherActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execut e(InProcessGradleLauncherActionExecuter.java:25)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction. execute(CommandLineActionFactory.java:200)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction. execute(CommandLineActionFactory.java:173)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute( CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute( CommandLineActionFactory.java:138)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots trap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j ava:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26) Caused by: : java.lang.NoClassDefFoundError: org/jaxen/Navigator
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav a:116)
at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(Bas icAntBuilder.java:71)
at org.gradle.api.internal.project.AntBuilderDelegate.nodeCompleted(Defa ultIsolatedAntBuilder.groovy:172)
at org.gradle.api.plugins.quality.Pmd$_run_closure1.doCall(Pmd.groovy:81 )
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:141)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:90)
at org.gradle.util.ConfigureUtil$configure.call(Unknown Source)
at org.gradle.api.internal.project.DefaultIsolatedAntBuilder.execute(Def aultIsolatedAntBuilder.groovy:112)
at org.gradle.api.internal.project.IsolatedAntBuilder$execute.call(Unkno wn Source)
at org.gradle.api.plugins.quality.Pmd.run(Pmd.groovy:79)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMeth od(BeanDynamicObject.java:216)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObj ect.java:122)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(Composite DynamicObject.java:147)
at org.gradle.api.plugins.quality.Pmd_Decorated.invokeMethod(Unknown Sou rce)
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF actory$4.execute(AnnotationProcessingTaskFactory.java:161)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF actory$4.execute(AnnotationProcessingTaskFactory.java:156)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra ctTask.java:472)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra ctTask.java:461)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:60)
… 58 more Caused by: java.lang.NoClassDefFoundError: org/jaxen/Navigator
at net.sourceforge.pmd.RuleSetFactory.parseSingleRuleNode(RuleSetFactory .java:309)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java: 253)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja va:209)
at net.sourceforge.pmd.RuleSetFactory.createSingleRuleSet(RuleSetFactory .java:135)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java :85)
at net.sourceforge.pmd.ant.PMDTask.doTask(PMDTask.java:220)
at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:334)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav a:106)
… 77 more Caused by: java.lang.ClassNotFoundException: org.jaxen.Navigator
… 86 more
BUILD FAILED
Total time: 5.625 secs
Googling for this, several Ant users seem to have the same problem (and Gradle’s PMD task is based on the Ant task). I couldn’t find a clear solution, and unfortunately I can’t reproduce the problem.
I had the same issue, and finally found a workaround, though not understanding why it’s required. I am able to reproduce.
Gradle 1.3 MAC OSX 10.8.2 Apple JDK 6
Project layout: -gradletest
_myproj (contains src-main-java and src-test-java)
_lib
_build.gradle
_settings.gradle
build.gradle (this one works fine):
subprojects {
apply {
plugin 'java'
plugin 'pmd'
}
repositories { mavenCentral() }
pmd {
ruleSetFiles=files("$rootDir/lib/all-java.xml")
ignoreFailures=true
}
}
However my organization forces us to use a common shared lib, so I have to use a flatDir repository. I inspected the dependency downloads above and put the .jars in my lib directory.
The following DOES NOT work and pmdMain fails with the NoClassDefFoundError: org/jaxen/Navigator error:
subprojects {
apply {
plugin 'java'
plugin 'pmd'
}
repositories { flatDir dirs: ["$rootDir/lib"] }
dependencies {
testCompile 'asm:asm:3.2','com.ibm.icu:icu4j:2.6.1',
'dom4j:dom4j:1.6.1','jaxen:jaxen:1.1.1',
'jdom:jdom:1.0','junit:junit:4.4',
'pmd:pmd:4.3','xalan:xalan:2.6.0',
'xerces:xercesImpl:2.6.2','xerces:xmlParserAPIs:2.6.2',
'xom:xom:1.0'
}
pmd {
ruleSetFiles=files("$rootDir/lib/all-java.xml")
ignoreFailures=true
}
}
The workaround that fixes the above issue - adding the dependencies specifically for pmd. Why would this be necessary?
subprojects {
apply {
plugin 'java'
plugin 'pmd'
}
repositories { flatDir dirs: ["$rootDir/lib"] }
dependencies {
testCompile 'asm:asm:3.2','com.ibm.icu:icu4j:2.6.1',
'dom4j:dom4j:1.6.1','jaxen:jaxen:1.1.1',
'jdom:jdom:1.0','junit:junit:4.4',
'pmd:pmd:4.3','xalan:xalan:2.6.0',
'xerces:xercesImpl:2.6.2','xerces:xmlParserAPIs:2.6.2',
'xom:xom:1.0'
pmd 'asm:asm:3.2','com.ibm.icu:icu4j:2.6.1',
'dom4j:dom4j:1.6.1','jaxen:jaxen:1.1.1',
'jdom:jdom:1.0','junit:junit:4.4',
'pmd:pmd:4.3','xalan:xalan:2.6.0',
'xerces:xercesImpl:2.6.2','xerces:xmlParserAPIs:2.6.2',
'xom:xom:1.0'
}
pmd {
ruleSetFiles=files("$rootDir/lib/all-java.xml")
ignoreFailures=true
}
}
After this build.gradle mod PMD runs ok and generates its report files.
Works as expected. PMD requires Jaxen. When resolving from a Maven repository, transitive dependency resolution takes care of pulling down Jaxen (which is listed as a dependency in PMD’s POM). When using a flat dir repository, you have to take care of transitive dependencies yourself.
Ah ok thanks did not realize pmd dependencies had to be explicitly set.