Download and Install
This guide demonstrates how to create a project and add the Kotlin Sync driver dependencies by using Gradle or Maven.
Create a Kotlin Project
First, make sure that your system has Kotlin installed and running on JDK 1.8 or later.
We recommend that you use an integrated development environment (IDE) such as IntelliJ IDEA or Eclipse IDE to configure Gradle or Maven to build and run your project.
Tip
If you are not using an IDE, see the Creating New Gradle Builds guide or the Building Maven guide for more information on how to set up your project.
For more information on getting started with Kotlin and creating your first project, see Get started with Kotlin/JVM in the Kotlin language documentation.
Add the Driver Bill of Materials
In your IDE, create a new Maven or Gradle project. Add the Bill of Materials (BOM) for MongoDB JVM artifacts to your project to organize dependency versions. The BOM simplifies dependency management by ensuring that you maintain consistent and compatible versions of dependencies, such as between the Kotlin Sync driver and the core driver library. Use the BOM to avoid version conflicts and simplify upgrades.
Select from the following Maven and Gradle tabs to view instructions for adding the BOM for each dependency manager:
Add the following code to the dependencyManagement
list in your
pom.xml
file:
<dependencyManagement> <dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-bom</artifactId> <version>5.4.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Add the following code to dependencies list in your
build.gradle.kts
file:
dependencies { implementation(platform("org.mongodb:mongodb-driver-bom:5.4.0")) }
To view a list of dependencies that the BOM manages, see the mongodb-driver-bom dependency listing on the Maven Repository website.
Add MongoDB as a Dependency
If you are using Gradle to manage your
packages, add the following entry to your build.gradle.kts
dependencies list:
dependencies { implementation("org.mongodb:mongodb-driver-kotlin-sync") }
If you are using Maven to manage your
packages, add the following entry to your pom.xml
dependencies list:
<dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-kotlin-sync</artifactId> </dependency> </dependencies>
Because you installed the BOM, you can omit a version in the Kotlin Sync driver dependency entry. The version you specify in the BOM determines the dependency versions to install.
After you configure your dependencies, ensure that they are available to your project by running the dependency manager and refreshing the project in your IDE.
Add Serialization Library Dependencies
To enable the driver to convert between Kotlin objects and BSON, the data format for documents in MongoDB, you must also add one or both of the following serialization packages to your application:
bson-kotlinx
(Recommended)bson-kotlin
If you are using Gradle to manage your packages, add one of the following
entries to your build.gradle.kts
dependencies list:
implementation("org.mongodb:bson-kotlinx") // OR implementation("org.mongodb:bson-kotlin")
If you are using Maven to manage your packages, add one of the following
entries to your pom.xml
dependencies list:
<dependency> <groupId>org.mongodb</groupId> <artifactId>bson-kotlinx</artifactId> </dependency> <!--OR--> <dependency> <groupId>org.mongodb</groupId> <artifactId>bson-kotlin</artifactId> </dependency>
After you configure your dependencies, ensure that they are available to your project by running the dependency manager and refreshing the project in your IDE.
To learn more about these packages, see Kotlin Serialization.
After you complete these steps, you have a new project directory and the driver dependencies installed.
Note
If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback by using the Rate this page tab on the right or bottom right side of this page.