# Set repositories and dependencies in a Maven project For your Kotlin Maven project, you can configure where Maven looks for artifacts beyond the default Maven Central repository and define the libraries your project depends on. ## Declare repositories By default, the `mavenCentral` repository is available for all Maven projects. To access artifacts in other repositories, specify a custom ID for the repository name and its URL in the `` section: ```XML spring-repo https://repo.spring.io/release ``` Note: If you declare `mavenLocal()` as a repository in a Gradle project, you may experience problems when switching between Gradle and Maven projects. For more information, see [Declare repositories](gradle-configure-project.html#declare-repositories). In general, to add a dependency on a library, you should declare a new `` entry in the `` section: ```XML org.jetbrains.kotlinx kotlinx-serialization-json 1.11.0 ``` ## Set dependencies ### Dependency on the standard library Kotlin has an extensive standard library that you can use in your applications. You can add the standard library dependency manually or enable the `` option to set it up automatically if it's missing. #### Automatic setup You can avoid manual configuration using the [<extensions> option](maven-configure-project.html#automatic-configuration) provided by the Kotlin Maven plugin. It automatically adds the `kotlin-stdlib` dependency if it's not defined in the project. For example, when you create a new Kotlin Maven project or introduce Kotlin to your existing Java Maven project. If you already declared a dependency `kotlin-stdlib`, for example, with a different version, the Kotlin Maven plugin with `` will not overwrite it. You can also opt out from the automatic addition of the standard library. For that, add the following to the `` section: ```XML false ``` Note: This property disables not only the automatic addition of the standard library, but also the registration of source root paths. Other `` features are not affected. #### Manual configuration To manually add Kotlin's standard library to your project, update the `dependencies` section in your `pom.xml` file with the following: ```XML org.jetbrains.kotlin kotlin-stdlib ${kotlin.version} ``` Note: If you're targeting JDK 7 or 8 with Kotlin versions older than: * 1.8, use `kotlin-stdlib-jdk7` or `kotlin-stdlib-jdk8`, respectively. * 1.2, use `kotlin-stdlib-jre7` or `kotlin-stdlib-jre8`, respectively. ### Dependencies on test libraries If your project uses [Kotlin reflection](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/) or testing frameworks, add the relevant dependencies. Use `kotlin-reflect` for the reflection library, and `kotlin-test` and `kotlin-test-junit5` for testing libraries: ```XML org.jetbrains.kotlin kotlin-reflect ${kotlin.version} org.jetbrains.kotlin kotlin-test-junit5 test ``` ### Dependency on a kotlinx library For kotlinx libraries, you can either add the base artifact name or the name with a `-jvm` suffix. Refer to the library's README file on [klibs.io](https://klibs.io/). For example, to add a dependency on [kotlinx.coroutines](https://kotlinlang.org/api/kotlinx.coroutines/) library: ```XML org.jetbrains.kotlinx kotlinx-coroutines-core 1.11.0 ``` To add a dependency on the [kotlinx-datetime](https://kotlinlang.org/api/kotlinx-datetime/) library: ```XML org.jetbrains.kotlinx kotlinx-datetime-jvm 0.8.0 ``` ## Manage dependencies with a BOM A [Bill of Materials (BOM)](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms) is a special POM file that manages dependency versions in your project. This keeps related artifacts aligned and avoids version conflicts. Kotlin publishes the [kotlin-bom](https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-bom) artifact, which specifies the versions of Kotlin libraries, such as `kotlin-stdlib`, `kotlin-reflect`, and `kotlin-test`, that correspond to the same Kotlin release. This is useful when other libraries in your project have transitive dependencies on Kotlin artifacts because it ensures that all dependencies resolve to the same Kotlin version. To use the Kotlin BOM, import it in the `` section of your `pom.xml` file as follows: ```XML org.jetbrains.kotlin kotlin-bom 2.4.21 pom import ``` After importing the BOM, you can declare Kotlin dependencies in the `` section without specifying their versions; they come from the BOM file automatically. * Importing a BOM doesn't add any dependencies to your project on its own. It only controls the versions of explicitly declared and transitive dependencies. * If you still specify a `` for a dependency, that value overrides the version from the BOM. If your project publishes several libraries that are released together, you can provide your own BOM so that users can align the versions of those libraries in the same way. To learn how to author your own BOM, see the [Maven documentation](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms). ## What's next? [Configure Kotlin compiler](maven-kotlin-compiler.html)