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 17
- 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 17 JDK version.
- In the download dialog, select version 17 and vendor Eclipse Temurin (AdoptOpenJDK HotSpot).
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 17 JDK for running Maven when importing the project.
- Ensure that the JRE setting in Maven → Runner dialog is set to Use Project JDK.
caution
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 8.37.
- 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:
Eclipse
Follow these instructions to configure your Eclipse setup.