This document outlines the process to set up a development environment for the Hedera Mirror Node project. It covers the required software, environment setup, IDE configurations, project compilation, and how to run tests.
To contribute to the Hedera Mirror Node project, you need to install the following software and tools:
Hedera Mirror Node requires Java 21 or a later version for development.
-
Install Java 21:
On Ubuntu and macOS:
curl -s "https://get.sdkman.io" | bash sdk install java 21-tem
-
Verify Installation:
java -version
-
You should see output similar to:
openjdk version "21.0.4" 2024-XX-XX
If you are managing multiple Java versions, you can use the sdk tool to switch to Java 21:
sdk use java 21-tem
Docker is used to manage and run containerized services (such as databases) for the mirror node.
-
Install Docker:
On Ubuntu:
sudo apt update sudo apt install docker.io sudo systemctl enable docker --now sudo usermod -aG docker $USER # Optional: allows non-root access
On macOS:
brew install --cask docker open /Applications/Docker.app
-
Verify Installation:
docker --version
We follow best practices to ensure that code quality and maintainability remain high. Below are the key coding standards to follow:
- Java Coding Style: Follow the Google Java Style Guide for writing clean and readable Java code.
- Kotlin Style: Follow the Kotlin Style Guide for Kotlin-based files.
- Spotless Plugin: The project uses the Spotless plugin to enforce consistent formatting. You can run this before
submitting code:
./gradlew spotlessApply
We recommend using IntelliJ IDEA or Eclipse for developing the Hedera Mirror Node. Below are configuration steps for IntelliJ IDEA.
-
Install IntelliJ IDEA:
- Download from IntelliJ IDEA website.
-
Set up Project SDK:
- Go to
File > Project Structure > Project
. - Set Project SDK to
Java 21
(or higher). - Set Project language level to
21 - Record patterns, pattern matching for switch
.
- Go to
-
Gradle Configuration:
- Ensure Gradle JVM is set to Java 21: Go to
File > Settings > Build, Execution, Deployment > Build Tools > Gradle
and set the Gradle JVM to Java 21.
- Ensure Gradle JVM is set to Java 21: Go to
-
Enable Save Actions:
- Go to
File > Settings > Tools > Actions on Save
- Enable the following save actions:
Reformat code
: Ensures consistent code style by reformatting code on save.Optimize imports
: Automatically removes unused imports and arranges them.Rearrange code
: Arranges code based on predefined rules.Run code cleanup
: Cleans up unnecessary elements in the code.Build project
: Automatically builds the project upon saving if needed.
- Go to
-
Import Java Code Style:
Download
the Java code file located in the repository at docs/palantir-style.xml- In IntelliJ, go to
File > Settings > Editor > Code Style
. - Click on
Java
underCode Style
. - In the Code Style section for Java, look for an option to import the downloaded code style file. This can
typically be found by clicking on the
gear icon (⚙️)
or theScheme dropdown
. - Choose
Import Scheme > IntelliJ IDEA code style XML
or a similar option. Import
the downloaded Java code style file to ensure consistent formatting across the project.
-
Enable Docker Integration:
- Enable Docker integration in IntelliJ if you are running containerized services directly from the IDE.
The Hedera Mirror Node uses Gradle for building and managing dependencies.
-
Clean and Build the Project: Run the following command to clean and build the project:
./gradlew clean build
This command will:
- Clean previous builds.
- Compile the source code.
- Download any required dependencies.
- Run tests.
-
Compile Specific Subprojects: If you want to build a specific subproject (e.g.,
monitor
), run:./gradlew :monitor:build
You can run the project’s tests using Gradle.
-
Run All Tests: To run all the tests, use:
./gradlew test
-
Run Tests for a Specific Subproject: To run tests for a specific subproject (e.g.,
common
):./gradlew :common:test
-
Running Specific Tests: You can also run specific test classes or methods:
./gradlew test --tests "*YourTestClassName"
or:
./gradlew test --tests "*YourTestClassName.yourTestMethodName"
The mirror node often depends on containerized services such as PostgreSQL or Redis. These services are
defined in docker-compose
files within the repository.
-
Start Docker Services: To start all services needed for local development:
docker compose up
-
Stop Docker Services: To stop the services:
docker compose down
For production or deployment, you may need to generate Docker images.
-
Build Docker Images: You can build Docker images using Gradle and specify custom properties to control the platform, registry, and tag for the Docker image.
./gradlew dockerBuild \ -PdockerPlatform=linux/amd64 \ -PdockerRegistry=docker.io \ -PdockerTag=1.0.0-SNAPSHOT
-
Push Docker Images: After building the Docker image, you can push it to the specified Docker registry to make it available for use in a remote Kubernetes environment.
./gradlew dockerPush \ -PdockerPlatform=linux/amd64 \ -PdockerRegistry=docker.io \ -PdockerTag=1.0.0-SNAPSHOT
NB: Ensure you are logged into the Docker registry if authentication is required. This command will push the image with the specified tag to the registry.