This guide explains how to make changes to ZAP using IntelliJ IDEA.
Working with ZAP in IntelliJ IDEA may need a bit more Java resources for the Gradle actions. To adjust how much memory Gradle can use on your machine set the option in gradle.properties
echo 'org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=1g' >> ~/.gradle/gradle.properties
echo "org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=1g" >> %USERPROFILE%\.gradle\gradle.properties
On the welcome screen of IntelliJ IDEA, click on ‘New Project’. In the New Project window, select ‘Empty Project’ and click on Next. Choose a Project name (e.g. “ZAP Development Environment”) and pick a location of your choice. Click on Finish.
In the ‘Project Structure’ window that pops up next, pick an installed JDK.
In the same window, select the ‘Modules’ tab under ‘Project Settings’, click on the ➕ button, and select ‘Import Module’.
Then, in the ‘Select File or Directory to Import’ window, navigate to any one of the cloned ZAP repositories, select the ‘build.gradle.kts’ file that is present in the root of its directory, and click on OK.
Repeat the last two steps until you have imported all of the ZAP repositories as modules. Then, click on OK in the ‘Project Structure’ window.
You should now be able to see all the imported repositories in the IntelliJ IDEA Project tab.
It is worth noting that some of the zap-extensions add-ons may fail to compile if you do not have the required environment for them. This is to be expected and is not a problem unless you want to work on those add-ons, in which case see their READMEs for more details.
In the IntelliJ Project tab navigate to:
- zaproxy / zap / src / main / java / org / zaproxy / zap
Right click on
ZAP and select ‘Run ZAP.main()’.
In case you are unable to see this option, go to ‘View’ → ‘Tool Windows’ → ‘Gradle’. Then, in the Gradle tab, click on the ‘Reload All Gradle Projects’ button before trying this step again.
ZAP will now start but it is not set up quite right and may show warning dialogs, so close it and go back to IntelliJ.
Select the ‘Run’ → ‘Edit Configurations…’ and then the
ZAP configuration under ‘Application’.
Change the ‘Working directory’ by browsing to:
.../zaproxy should be replaced by the complete path to the cloned zaproxy repository on your system.
Click on Apply and try running ZAP again. ZAP should now start with all of the add-ons correctly configured.
You can run the ZAP Gradle tasks from the command line or from within IntelliJ IDEA - the end result will be the same.
IntelliJ has a ‘Gradle’ tab that lists all of the tasks available to you ordered by project. You can view this tab by going to ‘View’ → ‘Tool Windows’ → ‘Gradle’.
Note that the add-ons in zap-extensions all have their own set of tasks in addition to the top level ones.
Sometimes IntelliJ will unexpectedly fail to compile ZAP code. This can occur if you switch between git branches which have different dependencies.
If this happens to you then right click on the relevant project in the Gradle tab and select ‘Reload Gradle Project’.
If that doesn’t work either, try doing ‘File’ → ‘Invalidate Caches / Restart…’.
Do you have any other Tips and Tricks for working on ZAP using IntelliJ IDEA? If so then send a PR to update this page - you can use the ‘Edit on GitHub’ link in the footer.