Pmd 5.0(.1) not supported?


(px) #1

Hello,

it seems pmd 5.0.0/5.0.1 is not supported by gradle.

Trying to use it results in the following FAILURE:

  • What went wrong: Could not resolve all dependencies for configuration ‘:main:pmd’. > Could not find pmd:pmd:5.0.0.

Required by:

PG:main:0.0.0-SNAPSHOT

It seems this is caused by pmd using a different maven groupId (net.sourceforge.pmd:pmd:$pmdVersion instead of pmd:pmd:$pmdVersion) since V5.0.0.

Any chance to use pmd 5?


(René Groeschke) #2

Hello, this issue was just fixed on master by a pull request but this fix was not part of the gradle 1.4 release. To use pmd >= 5 you have to use the latest nightly from http://www.gradle.org/nightly

cheers, René


(Josh Reed) #3

I can’t get pmd to work with >=5 and I am using gradle v1.6

These scenarios work:

dependencies {
    pmd 'pmd:pmd:4.2.6'
}

and this works

dependencies {
    compile 'net.sourceforge.pmd:pmd:5.0.3'
}

However, this does not work:

dependencies {
    pmd 'net.sourceforge.pmd:pmd:5.0.3'
}

StackTrace:

:pmdMain FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':pmdMain'.
> Can't find resource null.
Make sure the resource is a valid file or URL or is
 on the CLASSPATH.
Here's the current classpath: C:\Users\Josh Reed\Programming
\installations\gradle-1.6\lib\gradle-launcher-1.6.jar
  * 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:69)
        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:35)
        at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskE
xecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
aultCacheAccess.java:179)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
aultCacheAccess.java:232)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning
Operation(DefaultPersistentDirectoryStore.java:142)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStat
eCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
        at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskE
xecuter.execute(CacheLockReleasingTaskExecuter.java:33)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.e
xecute(ContextualisingTaskExecuter.java:34)
        at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskE
xecuter$1.run(CacheLockAcquiringTaskExecuter.java:39)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
ess.java:124)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
ess.java:112)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(De
faultPersistentDirectoryStore.java:134)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStat
eCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
        at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskE
xecuter.execute(CacheLockAcquiringTaskExecuter.java:37)
        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:282)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(De
faultTaskPlanExecutor.java:48)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(De
faultTaskPlanExecutor.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
tTaskPlanExecutor.java:27)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
ltTaskGraphExecuter.java:89)
        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.state.TaskCacheLockHandlingBu
ildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
ess.java:124)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
ess.java:112)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(De
faultPersistentDirectoryStore.java:134)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStat
eCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
        at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBu
ildExecuter.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:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:35)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBu
ild.java:45)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(Build
CommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(
WatchForDisconnection.java:42)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute
(ResetDeprecationLogger.java:24)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execut
e(StartStopIfBuildAndStop.java:33)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnRes
ult.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(Forw
ardClientInput.java:70)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(Forw
ardClientInput.java:68)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(For
wardClientInput.java:68)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClien
t.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(Build
CommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBu
ild(EstablishBuildEnvironment.java:59)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(Build
CommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.
run(StartBuildOrRespondWithBusy.java:45)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(D
aemonStateCoordinator.java:186)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.do
Build(StartBuildOrRespondWithBusy.java:49)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(Build
CommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.
java:36)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.e
xecute(CatchAndForwardDaemonFailure.java:32)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed
(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.e
xecuteCommand(DefaultDaemonCommandExecuter.java:48)
        at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$Co
nnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
        at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$Co
nnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128
)
        at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$Co
nnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
        at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecut
orImpl$1.run(DefaultExecutorFactory.java:66)
Caused by: : Can't find resource null.
Make sure the resource is a valid file o
r URL or is on the CLASSPATH.
Here's the current classpath: C:\Users\Josh Reed\
Programming\installations\gradle-1.6\lib\gradle-launcher-1.6.jar
        at net.sourceforge.pmd.ant.PMDTask.doTask(PMDTask.java:177)
        at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:321)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        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_closure2.doCall(Pmd.groovy:10
2)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedActi
on.java:58)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:133)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:94)
        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:100)
        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$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:526)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:509)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
        ... 88 more
Caused by: net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource nul
l.
Make sure the resource is a valid file or URL or is on the CLASSPATH.
Here'
s the current classpath: C:\Users\Josh Reed\Programming\installations\gradle-1.6
\lib\gradle-launcher-1.6.jar
        at net.sourceforge.pmd.RuleSetReferenceId.getInputStream(RuleSetReferenc
eId.java:254)
        at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
161)
        at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:126)
        at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:111)
        at net.sourceforge.pmd.ant.PMDTask.doTask(PMDTask.java:173)
        ... 113 more
    BUILD FAILED
  Total time: 4.163 secs

Just found the source code, haven’t gotten to dig through it yet… PmdPlugin.groovy Pmd.groovy


(René Groeschke) #4

Hello, I think the problem in your sample code is the wrong groupId. PMD changed its groupId for pmd > 5.0. try this dependency definition:

dependencies {
    pmd 'pmd:pmd:5.0.3'
}

Can you try this and check if that fixes your issue? I admit the error message should be more helpful.

cheers, René


(Peter Niederwieser) #5

I’ve bumped our integration test from 5.0.1 to 5.0.3/5.0.4, and it works fine. Can you show your full PMD configuration? The idiomatic way to set the PMD version is ‘pmd { toolVersion = ‘5.0.4’ }’ (instead of declaring a PMD dependency).


(Josh Reed) #6

using windows 7 (64 bit version) with gradle 1.6

java -version info
Java version "1.7.0"
Java Runtime Encironment (build
1.7.0-b147)
Java Hotspot 64Bit Server VM - (build 21.0-b17, mixed mode)

gradle Info…

------------------------------------------------------------
Gradle 1.6
------------------------------------------------------------
  Gradle build time: Tuesday, May 7, 2013 9:12:14 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.7.0 (Oracle Corporation 21.0-b17)
OS: Windows 7 6.1 amd64

Here is the gradle file I have been playing around with…

apply plugin: "java"
apply plugin: "pmd"
  sourceSets {
 main {
  java {
   srcDir 'src'
  }
  resources {
   srcDir 'resources/src'
  }
 }
 test {
  java {
   srcDir 'test'
  }
  resources {
   srcDir 'resources/test'
  }
 }
}
    pmd {
 toolVersion = "5.0.4"
 println "${toolVersion}"
 ignoreFailures = true
 ruleSets = ['basic', 'design', 'braces', 'unusedcode', 'codesize', 'controversial', 'coupling', 'naming', 'javabeans' , 'typeresolution']
}
  test {
 forkEvery = 10
 maxParallelForks = 4
}
  configurations {
 runtime {
  transitive = false
 }
}
  repositories{
 mavenCentral()
}
  dependencies {
 //pmd 'pmd:pmd:5.0.3'
      //pmd 'net.sourceforge.pmd:pmd:5.0.4'
   compile fileTree(dir:'lib', include: '*.jar')
 testCompile 'org.testng:testng:6.8.+'
}
  archivesBaseName = 'testing-sample'
version = '0.0.1'
  sourceCompatibility = JavaVersion.VERSION_1_7
  def dateTime = new Date()
  manifest = manifest {
 attributes(
  'Package-Name' : 'Testing Sample',
  'Version' : version + ' - ' + dateTime.format('MMM dd yyyy'),
  'Compiled-With-Jvm-Version' : JavaVersion.current()
 )
}
  //Need to explicity set manifest on jar task
jar.manifest.from manifest
  project.description = 'Simple project'
def something = "Custom Property"
    task simple(description: "Simple Task") << {
 println "Running simple task for project " + project.description
 }
    task first(description: "First Task") << {
 println "Running first task!"
 }
    task showProperties << {
 println "Version: $version"
 println "Custom property: $something"
 println "Java Version: ${JavaVersion.current()}"
 }
       task sourceSetJavaProperties << {
 sourceSets {
  main {
   println "java.srcDirs = ${java.srcDirs}"
   println "resources.srcDirs = ${resources.srcDirs}"
   println "java.files = ${java.files.name}"
   println "allJava.files = ${allJava.files.name}"
   println "resources.files = ${resources.files.name}"
   println "allSource.files = ${allSource.files.name}"
   println "output.classesDir = ${output.classesDir}"
   println "output.resourcesDir = ${output.resourcesDir}"
   println "output.files = ${output.files}"
  }
 }
 }
    tasks.addRule("Pattern: desc<TaskName>: show description of a task."){
 taskName ->
 if (taskName.startsWith("desc")) {
  def targetTaskName = taskName - 'desc'
  def targetTaskNameUncapitalize = targetTaskName[0].toLowerCase() + targetTaskName[1..-1]
  def targetTask = project.tasks.findByName(targetTaskNameUncapitalize)
  if(targetTask) {
   task(taskName) << {
    println "Description of task ${targetTask.name} -> ${targetTask.description}"
   }
  }
 }
 }
    test.useTestNG()

I have tried doing

dependencies {
    pmd 'pmd:pmd:5.0.3'
}

and

pmd { toolVersion = '5.0.4' }

Still no luck. Maybe there is something wrong in my build.gradle file?

I am just typing “gradle -s check” on the command line…

Also from what I can tell the groupId changed to “net.sourceforge.pmd” when version 5 was released? Link where I got the maven info from

Just have been following along with the “Gradle Effective Implementation Guide” Book and I know it’s based off of gradle version 1.0.0 rc2, so I might be doing something that has been changed. But it’s weird that this works fine when I use pmd version 4.2.6 or 4.3…

Thanks.


(Peter Niederwieser) #7

Try with a single rule set, for example ‘java-basic’. Note that rule sets have been renamed in PMD 5 (e.g. ‘basic’ => ‘java-basic’).


(Josh Reed) #8

Okay,

I have narrowed it down to one line failing. I guess the error message isn’t helpful at all, as to what the real issue is.

So this line works fine for versions 4.3 and less, but not for >=5

ruleSets = ['basic', 'design', 'braces', 'unusedcode', 'codesize', 'controversial', 'coupling', 'naming', 'javabeans' , 'typeresolution']

Update: Just saw your post… Okay, yeah, the renaming thing is throwing me off.

If you look in the documentation the example still shown is for Link to documentation for RuleSet

The built-in rule sets to be used. See the official list of built-in rule sets. Example: ruleSets = ["basic", "braces"]

Thanks for your help…