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 <repositories> section:
In general, to add a dependency on a library, you should declare a new <dependency> entry in the <dependencies> section:
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 <extensions> option to set it up automatically if it's missing.
Automatic setup
You can avoid manual configuration using the <extensions> option 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 <extensions> will not overwrite it.
You can also opt out from the automatic addition of the standard library. For that, add the following to the <properties> section:
Manual configuration
To manually add Kotlin's standard library to your project, update the dependencies section in your pom.xml file with the following:
Dependencies on test libraries
If your project uses Kotlin reflection or testing frameworks, add the relevant dependencies. Use kotlin-reflect for the reflection library, and kotlin-test and kotlin-test-junit5 for testing libraries:
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.
For example, to add a dependency on kotlinx.coroutines library:
To add a dependency on the kotlinx-datetime library:
Use BOM dependency mechanism
To use a Kotlin Bill of Materials (BOM), add a dependency on kotlin-bom: