This guide explains, how to import the source code of PMD into your favorite IDE and start hacking on PMD.
This guide does not explain, how to use a PMD plugin in your favorite IDE, for this see, please see Plugins and Tools / Integrations.
Note: this is WIP - once this documentation is matured, it will be moved to the official documentation.
shell
$ git clone https://github.com/johndoe/pmd.git --depth=10 --no-tags
See the [Newcomers' Guide] for detailed instructions.
This first step is needed regardless which IDE you are going to use.
Note: You can also clone the repository from within your IDE, but this is not described here in this guide.
Clone additionally the build-tools
repository. It contains some settings, we'll later use
for configuring IDE:
shell
$ git clone https://github.com/pmd/build-tools.git
Make sure, you have Java Platform (JDK) 11 installed. Note: You have to use java11 or later in order to build PMD - older java versions are not supported.
To make sure your Maven environment is correctly setup, we'll build pmd once:
shell
$ cd pmd
$ ./mvnw clean verify
This will help with Maven IDE integration. It may take some time, because it will download all dependencies,
so go brew some coffee to get ready for the steps to come.
eclipse
. You'll be asked for a workspace. It's recommended to use an extra, separate new workspace for PMD,File
, Import...
. In the dialog, select Maven / Existing Maven Projects
and click Next
.Root Directory
select the directory, into which PMD's repository has been cloned.Select All
and then Finish
.You might be asked about a missing m2e connectors for the kotlin plugin. You can simply select Resolve All Later
and ignore this problem for now.
Now all PMD projects are imported. This might take a while. All the projects will appear on the left inside
the Project Explorer
.
To verify, that the basics work, right-click on the pmd-java
project and select Run As -> JUnit Test
.
If everything is well, the project will be built and the unit tests are executed.
You probably get some build errors in some projects. Try to ignore them for now - at least some unit test
should be executed. See also "Known Issues" below.
Window
-> Preferences
Java / Code Style / Code Templates
:Import...
and choose the file eclipse/pmd-eclipse-codetemplates.xml
from the "build-tools" repository.Java / Code Style / Formatter
:Import...
and choose the file eclipse/pmd-eclipse-code-formatter.xml
from the "build-tools" repository.Java / Code Style / Clean Up
:Import...
and choose the file eclipse/pmd-eclipse-code-cleanup.xml
from the "build-tools" repository.Java / Code STyle / Organize Imports
:Import...
and choose the file eclipse/pmd-eclipse-imports.importorder
from the build-tools" repository.Apply and Close
We are going to install two plugins: The checkstyle plugin itself and the m2e-code-quality plugin, which seamlessly activates and configures checkstyle in eclipse according to the maven configuration of PMD.
Help
, Install New Software...
http://eclipse-cs.sourceforge.net/update/
into the text field and press enter.Next
http://m2e-code-quality.github.com/m2e-code-quality/site/latest
Next
Maven / Update project...
in the contextOK
.The designer lives now in a separate repository, that you'll need to clone first:
$ git clone https://github.com/pmd/pmd-designer.git
Import the designer project via menu File
, Import...
. In the dialog, select Maven / Existing Maven Projects
and click Next
.
Open the class net.sourceforge.pmd.util.fxdesigner.DesignerStarter
via menu "Navigate / Open Type...".
Right click in the editor window and select "Run as -> Java Application".
pmd-apex, pmd-dist, pmd-doc and other projects are missing the project "pmd-apex-jorje". The project is actually
existing, but it is not a java project in eclipse.
Workaround:
$ ./mvnw clean install -f pmd-apex-jorje/pom.xml
Many tests depend on kotlin. Kotlin is not really supported in Eclipse. As long as you don't need to change
the kotlin tests, you can ignore this for now. In order to be able to execute the tests, there is a similar
workaround:
Build the project "pmd-lang-test" once from outside eclipse: $ ./mvnw clean install -f pmd-lang-test/pom.xml
This installs this module in your local maven repository.
In eclipse, close the project "pmd-lang-test". That way, eclipse will use the jar file (which contains
the already compiled kotlin base test classes) from the local maven repository instead.
pmd-scala project has no source code / tests: If you don't want to work on scala, then you can simply
close all scala projects.
For scala, there are two versions: 2.12 and 2.13. Both share the same code, which is in
pmd-scala-modules/pmd-scala-common
. However, this code is not used directly, but referenced from the two
projects pmd-scala-moduls/pmd-scala_2.12
and pmd-scala-moduls/pmd-scala_2.13
. When working on scala,
it is recommended to close pmd-scala_2.12 and only work on pmd-scala_2.13. Then you need to configure
"pmd-scala_2.13" manually, so that eclipse finds the source folders:
pmd-scala-modules/pmd-scala-common/src/main/java
. Name it "src-main-java" and click "Finish".pmd-scala-modules/pmd-scala-common/src/main/resources
. Name it "src-main-resources".pmd-scala-modules/pmd-scala-common/src/test/java
and pmd-scala-modules/pmd-scala-common/src/test/resources
.bin/idea.sh
Open
and select the folder, into which PMD's repository has been cloned../mvnw clean verify
, as described in the preparationFile > Project Structure
(CTRL+ALT+SHIFT+S).If you don't have the Checkstyle plugin:
File > Settings
(CTRL+ALT+S) and navigate to "Plugins" on the leftOnce you have the Checkstyle plugin:
File > Settings
(CTRL+ALT+S) and navigate to "Tools > Checkstyle" on the lefthttps://raw.githubusercontent.com/pmd/build-tools/master/src/main/resources/net/sourceforge/pmd/pmd-checkstyle-config.xml
Import the code style settings (formatter) so that it conforms with our Checkstyle config.
To do that, go to File > Settings
(CTLR+ALT+S) then navigate to "Editor > Code Style > Java".
Click on the cogwheel symbol, choose "Import Scheme > IntelliJ IDEA code style XML" and choose the file
intellij-idea/PMD-code-style.xml
from the build-tools repository.
Take some time to tweak the inspections so that they conform to the code style, for example flagging switch statements
with no default
case. This takes some time but can make your code much cleaner.
To do that, go to File > Settings
then navigate to "Inspections > Java".
The designer lives now in a separate repository, that you'll need to clone first:
$ git clone https://github.com/pmd/pmd-designer.git
See Contributing Guide of the Designer for details.
-v
to the program arguments, to get debug outputpmd-ui
modulemvn process-resources -pl pmd-ui
.mvn compile
is quick to execute when your Maven dependency cache