During working on project arch4u-pmd we made several java-based pmd rules, configured them in XML-based ruleset our-rules.xml
, and published it as a plain java lib/artifact (io.github.abc:my-pmd-rules:0.1.0
) to our artifacts repository.
The artifact structure looks like this:
> unzip -l my-pmd-rules-0.1.0.jar
Archive: my-pmd-rules-0.1.0.jar
Length Date Time Name
--------- ---------- ----- ----
0 02-15-2022 00:24 META-INF/
139 02-15-2022 00:24 META-INF/MANIFEST.MF
0 02-15-2022 00:24 io/
0 02-15-2022 00:24 io/github/
0 02-15-2022 00:24 io/github/rules/
...
4781 02-15-2022 00:24 io/github/rules/MissingMandatoryAnnotation.class
...
1138 02-15-2022 00:24 io/github/rules/our-rules.xml
...
How we can add them to the Gradle project using pmd plugin?
We have to process the following materials/questions/answers:
- https://stackoverflow.com/search?page=2&tab=Relevance&q=pmd%20classpath
- ClassNotFoundException: Using custom java rule for PMD ruleset
- Gradle's PMD plugin: what are acceptable arguments?
- Adding a ruleset to PMD?
- Adding custom rules in PMD - class not found issue
- https://discuss.gradle.org/t/pmd-ruleset-not-available-in-classpath/7201
- https://discuss.gradle.org/t/custom-rules-with-pmd-plugin/5859/4
- How to configure PMD Auxiliary classpath in Sonar
- https://docs.gradle.org/current/userguide/pmd_plugin.html
- https://github.com/gradle/gradle/blob/master/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdPlugin.java
- Custom PMD rule with Gradle also don't work
tasks.withType(Pmd) { pmdClasspath += file("path/to/rules.jar") }