Setting up an IDE
Apache Pulsar is using lombok, so you have to ensure your IDE setup with required plugins.
IntelliJ IDEA
Configure Project JDK to JDK 21
- Open Project Settings. Click File → Project Structure → Project Settings → Project.
- Select the JDK version. From the JDK version drop-down list, select Download JDK... or choose an existing recent Java 21 JDK version installed by SDKMAN.
- In the download dialog, select version 17 and vendor Amazon Corretto.
Configure Java version for Maven
- Open Maven Importing Settings. Click Settings → Build, Execution, Deployment → Build Tools → Maven → Importing.
- For JDK for Importer setting, select Use Project JDK. This uses the Java 21 JDK for running Maven when importing the project.
- Ensure that the JRE setting in Maven → Runner dialog is set to Use Project JDK.
Some configuration in the Maven build is conditional based on the JDK version. Incorrect configuration gets chosen when the "JDK for Importer" isn't the same as the "Project JDK".
Configure annotation processing
- Open Annotation Processors Settings. Click Settings → Build, Execution, Deployment → Compiler → Annotation Processors.
- Select the following buttons:
- Enable annotation processing
- Obtain processors from project classpath
- Store generated sources relative to: Module output directory
- Set the generated source directories to be equal to the Maven directories:
- Set "Production sources directory:" to "generated-sources".
- Set "Test sources directory:" to "generated-test-sources".
- Click OK.
- Install the lombok plugin in intelliJ.
Configure code style
- Open Code Style Settings dialog box by going to Settings → Editor → Code Style.
- Click on the ⚙ symbol → Import scheme → IntelliJ IDEA code style XML
- Pick the file
${pulsar_dir}/src/idea-code-style.xml
- On the dialog box that opens, click OK.
- Ensure the scheme you just created is selected in Scheme dropdown then click OK.
Configure Checkstyle
- Install the Checkstyle-IDEA plugin.
- Open Checkstyle Settings. Click Settings → Tools → Checkstyle.
- Set Checkstyle version to 10.14.2.
- Set Scan scope to Only Java sources (including tests).
- Click + button in the Configuration section to open a dialog to choose the checkstyle config file.
- Enter a Description. For example, Pulsar.
- Select Use a local checkstyle file.
- Set File to buildtools/src/main/resources/pulsar/checkstyle.xml.
- Select Store relative to project location.
- Click Next → Next → Finish.
- Activate the configuration you just added by toggling the corresponding box.
- Click OK.
Further configuration
- When working on the Pulsar core modules in IntelliJ, reduce the number of active projects in IntelliJ to speed up IDE actions and reduce unrelated IDE warnings.
- In IntelliJ's Maven UI's tree view under "Profiles"
- Activate "core-modules" Maven profile
- De-activate "main" Maven profile
- Run the "Reload All Maven Projects" action from the Maven UI toolbar. You can also find the action by the name in the IntelliJ "Search Everywhere" window that gets activated by pressing the Shift key twice.
- In IntelliJ's Maven UI's tree view under "Profiles"
- Run the "Generate Sources and Update Folders For All Projects" action from the Maven UI toolbar. You can also find the action by the name in the IntelliJ "Search Everywhere" window that gets activated by pressing the Shift key twice. Running the action takes about 10 minutes for all projects. This is faster when the "core-modules" profile is the only active profile.
Troubleshooting
- In the case of compilation errors with missing Protobuf classes, ensure to run the "Generate Sources and Update Folders For All Projects" action.
- When all the Pulsar source code doesn't compile properly in IntelliJ and there are compilation errors:
- Use the "core-modules" profile if working on the Pulsar core modules since the source code for those modules can be compiled in IntelliJ.
- Sometimes it might help to mark a specific project ignored in IntelliJ Maven UI by right-clicking the project name and select Ignore Projects from the menu.
- Currently, it is not always possible to run unit tests directly from the IDE because of the compilation issues. As a workaround, individual test classes can be run by using the
mvn test -Dtest=TestClassName
command.
- The above steps have all been performed, but a test still won't run.
- In this case, try the following steps:
- Close IntelliJ.
- Run
mvn clean install -DskipTests
on the command line. - Reopen IntelliJ.
- If that still doesn't work:
- Verify Maven is using a supported version. Currently, the supported version of Maven is specified in the
<requireMavenVersion>
section of the rootpom.xml
file. - Try "restart and clear caches" in IntelliJ and repeat the above steps to reload projects and generate sources.
- Verify Maven is using a supported version. Currently, the supported version of Maven is specified in the
- In this case, try the following steps:
Visual Studio Code (VS Code)
Before starting, make sure you have installed the Java Extension Pack in VS Code.
Since multiple versions of Java are used for Pulsar development, it is recommended to use SDKMAN to manage different versions of Java. The separate guide how to setup build tools explains how to install Java 17 and 21 using SDKMAN.
Once you have installed the Java versions using SDKMAN, you can add (or modify) the following settings to your VS Code User level settings.json
file. Please check VS Code documentation for more details. The simplest way to open the settings file is to run the Preferences: Open Settings (JSON)
command from the Command Palette (Ctrl+Shift+P
or Cmd+Shift+P
on Mac).
{
"java.jdt.ls.vmargs": "-Xmx6g -XX:+UseZGC -XX:+ZGenerational -Dsun.zip.disableMemoryMapping=true",
"java.jdt.ls.java.home": "~/.sdkman/candidates/java/21",
"java.configuration.runtimes": [
{
"name": "JavaSE-21",
"path": "~/.sdkman/candidates/java/21",
"default": true
},
{
"name": "JavaSE-17",
"path": "~/.sdkman/candidates/java/17"
}
],
"java.autobuild.enabled": false,
"java.debug.settings.onBuildFailureProceed": true,
"java.compile.nullAnalysis.mode": "disabled",
"java.configuration.updateBuildConfiguration": "interactive"
}
If the java.jdt.ls.java.home
setting doesn't point to a Java 21 JDK, you must remove -XX:+ZGenerational
from java.jdt.ls.vmargs
setting since Java 21 is the first version that supports generational ZGC.
The java.autobuild.enabled
setting is set to false
since building the Pulsar project in VS Code takes very long time.
The java.debug.settings.onBuildFailureProceed
is set to true
so that tests can be run even when there are individual build failures.
Before running tests, you need to build the project manually at least once using the following command:
mvn -Pcore-modules,-main -T 1C clean install -DskipTests -Dspotbugs.skip=true -Dcheckstyle.skip=true -Dlicense.skip=true -DnarPluginPhase=none
This will make the protobuf / lightproto generated classes available to the tests run in the IDE. Without this there will be errors at runtime about missing classes or Mockito related errors.
For troubleshooting, please check Language support for Java extension documentation. Adding "java.transport": "stdio"
to the settings can help display errors in the error log if the problem is related to the language server.
Eclipse
Follow these instructions to configure your Eclipse setup.