Kotlin Help

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:

  1. In the <properties> section, define the version of Kotlin you want to use in the kotlin.version property:

    <properties> <kotlin.version>2.3.20</kotlin.version> </properties>
  2. In the <build><plugins> section, add the Kotlin Maven plugin:

    <build> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> </plugin> </plugins> </build>
  3. (Optional) You can also enable the extensions option to simplify project configuration. To do so, update the Kotlin Maven plugin section in your `pom.xml` file:

    <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <extensions>true</extensions> <!-- Add this extension --> </plugin> </plugins>

    The extensions option in the Kotlin Maven plugin automatically:

    • Registers src/main/kotlin and src/test/kotlin directories as source roots if they already exist but are not specified in the plugin configuration.

    • Adds the kotlin-stdlib dependency if it's not already defined in the project.

Use JDK 17

To use JDK 17, in your .mvn/jvm.config file, add:

--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED

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:

<repositories> <repository> <id>spring-repo</id> <url>https://repo.spring.io/release</url> </repository> </repositories>

Set dependencies

To add a dependency on a library, include it in the <dependencies> section:

<dependencies> <dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-serialization-json</artifactId> <version>1.10.0</version> </dependency> </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.

Manual configuration

To manually add the Kotlin's standard library to your project, update the dependencies section in your pom.xml file with the following:

<dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <!-- Uses the kotlin.version property specified in <properties/>: --> <version>${kotlin.version}</version> </dependency> </dependencies>

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.

You can also opt out from the automatic addition of the standard library. For that, add the following to the <properties> section:

<project> <properties> <kotlin.smart.defaults.enabled>false</kotlin.smart.defaults.enabled> </properties> </project>

Note that this property disables all simplified setup features, including the registration of source root paths.

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:

<dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-reflect</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-test-junit5</artifactId> <scope>test</scope> </dependency> </dependencies>

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:

<dependencies> <dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-coroutines-core</artifactId> <version>1.10.2</version> </dependency> </dependencies>

To add a dependency on the kotlinx-datetime library:

<dependencies> <dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-datetime-jvm</artifactId> <version>0.7.1</version> </dependency> </dependencies>

Use BOM dependency mechanism

To use a Kotlin Bill of Materials (BOM), add a dependency on kotlin-bom:

<dependencyManagement> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-bom</artifactId> <version>2.3.20</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

What's next?

Compile and package your Kotlin Maven project

17 March 2026