I have searched google, but I am not able to find any primer on this topic.
3 Answers
As the original contributor of the PMD Apex language module all I can add here is to clarify a common misunderstanding that is the root for many confusion here on StackExchange:
There are two PMD tools out there:
The original Open-Source PMD - the well-known open-source code analyzer that support many languages and can be extended and improved by the community.
The **Closed-source ApexPMD(a.k.a CodeScan) - a paid PMD clone by an Australian company called VillageChief. ApexPMD uses PMD under the hood.
Which one should you use?
As the original contributor of the Apex module to PMD I might be biased, but I think in the long run developers will definitely profit from going with a flexible open source solution. Why?
Features: There might be no feature-parity between PMD and ApexPMD right now but the more developer and companies jump on the #CleanApex bandwagon the more contributions we will see. No small company can then compete with that velocity.
Integrations/Tooling: Since my initial contribution many tooling providers integrated PMD into their products. Let me just name a few. Salesforce IDEs like Illuminated Cloud, The WelkinsSuite, vscode & Force.com IDE. Github and Bitbucket integrators like CodeClimate and Codacy.
Salesforce.com favors Open-Source: Salesforce.com is actively supporting my work on PMD for Apex. They donated a parser and added features to Apex that make life easier for us writing PMD rules. There are even plans to make the PMD Eclipse plugin part of their Force.com IDE 2.
Become part of the community at https://github.com/pmd/pmd/issues. :-)
-
Hi Robert, would you consider writing a tutorial on how to use PMD with Apex? This page has no information pmd.github.io/latest/pmd_rules_apex.html– Andy RayCommented Nov 13, 2019 at 20:43
-
No need to consider this as in the last years a ton of great material has been produced. I did a google and was impressed. You might like this blog.deadlypenguin.com/blog/2018/07/06/… or my recent Pluralsight course pluralsight.com/courses/… Commented Nov 13, 2019 at 20:50
-
Even more material can be found here: pmd.github.io/latest/pmd_projectdocs_trivia_news.html Commented Jan 19, 2021 at 10:13
PMD is very well known source code analyzer for Java, android and many more languages. Its also supports Apex.
There are multiple ways in which we can use PMD
- We can run static code analysis standalone
- It can be part of ANT build to generate error reports
- Jenkins can use it to generate nice report around code quality
- Eclipse can use it as a plugin to generate report
Check this link, PMD is a static source code analyser for Java. I. Found this previously asked question helpful as I also use Eclipse:
Basically when someone references "Apex PMD" they are simply talking about the fact that PMD now supports the Apex language.
Just to include a link here too, for me the most helpful prt was this blog article by Jitendra Zara