Configure a Maven project
To build a Kotlin project with Maven, you need to add the Kotlin Maven plugin to your pom.xml build file, declare repositories, and configure the project's dependencies.
Enable and configure the plugin
The kotlin-maven-plugin compiles Kotlin sources and modules. Currently, only Maven v3 is supported.
To apply the Kotlin Maven plugin, update your pom.xml build file as follows:
In the
<properties>section, define the version of Kotlin you want to use in thekotlin.versionproperty:<properties> <kotlin.version>2.3.0</kotlin.version> </properties>In the
<build><plugins>section, add the Kotlin Maven plugin:<plugins> <plugin> <artifactId>kotlin-maven-plugin</artifactId> <groupId>org.jetbrains.kotlin</groupId> <version>2.3.0</version> </plugin> </plugins>
Use JDK 17
To use JDK 17, in your .mvn/jvm.config file, add:
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:
Set dependencies
To add a dependency on a library, include it in the <dependencies> section:
Dependency on the standard library
Kotlin has an extensive standard library that you can use in your applications. To use the standard library in your project, add the following dependency to your pom.xml file:
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: