Enabling jar in classpath when starting PMdle plugin Gradle

I am trying to run PMD with a custom rule set file, but this rule set includes a rule, which is a regular class. This class exists in the bank, which is not delayed as a dependency, but instead enters a zip file (which is dependent) and is unpacked. Imagine the PMD rule class is only in build/extralib/blah.jar .

How to include this in my classpath when starting PMD? What I tried but did not work:

 pmd { ruleSetFiles = files("build/utils/pmd-rules.xml") pmdClasspath = files("build/extralib") } 

To be clear, the error is: java.lang.ClassNotFoundException: com.package.for.pmd.CrazyRule . This happens when pmdMain starts.

Secondary question: what is the difference between Pmd and PmdExtension ? Pmd has pmdClasspath , but PmdExtension does not. When I added pmdClasspath , I got:

Creating properties on demand (aka dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. Deprecated dynamic property: "pmdClasspath" on " org.gradle.api.plugins.quality.PmdExtension_Decorated@70221fc5 ", value: "file collection".

So, I suppose that he adheres only to PmdExtension? As a newbie to Gradle, this is a bit confusing ...

+4
source share
1 answer

When you configure pmd { ... } , you configure the extension. Sometimes you may need to go down to the task level and configure tasks.pmd { ... } . (Having an extension and a task with the same name is a common template used by code quality and IDE extensions / tasks.) The easiest way to add material to the PMD class path:

 dependencies { pmd ... } 

I have not tried if this works to add external rules, but it could be.

+5
source

Source: https://habr.com/ru/post/1486887/


All Articles