Edit Page

Using Maven

Plugin and Versions

The kotlin-maven-plugin compiles Kotlin sources and modules. Currently only Maven v3 is supported.

Define the version of Kotlin you want to use via kotlin.version. The correspondence between Kotlin releases and versions is displayed below:

Milestone Version
Release Candidate 1.0.0-rc-1036
Beta 4 1.0.0-beta-4589
Beta 3 1.0.0-beta-3595
Beta 2 1.0.0-beta-2423
Beta 1.0.0-beta-1103
Beta Candidate 1.0.0-beta-1038
M14 0.14.449
M13 0.13.1514
M12.1 0.12.613
M12 0.12.200
M11.1 0.11.91.1
M11 0.11.91
M10.1 0.10.195
M10 0.10.4
M9 0.9.66
M8 0.8.11
M7 0.7.270
M6.2 0.6.1673
M6.1 0.6.602
M6 0.6.69
M5.3 0.5.998

Dependencies

Kotlin has an extensive standard library that can be used in your applications. Configure the following dependency in the pom file

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
</dependencies>

Compiling Kotlin only source code

To compile source code, specify the source directories in the tag:

<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

The Kotlin Maven Plugin needs to be referenced to compile the sources:

<plugin>
    <artifactId>kotlin-maven-plugin</artifactId>
    <groupId>org.jetbrains.kotlin</groupId>
    <version>${kotlin.version}</version>

    <executions>
        <execution>
            <id>compile</id>
            <goals> <goal>compile</goal> </goals>
        </execution>

        <execution>
            <id>test-compile</id>
            <goals> <goal>test-compile</goal> </goals>
        </execution>
    </executions>
</plugin>

Compiling Kotlin and Java sources

To compile mixed code applications Kotlin compiler should be invoked before Java compiler. In maven terms that means kotlin-maven-plugin should be run before maven-compiler-plugin.

It could be done by moving Kotlin compilation to previous phase, process-sources (feel free to suggest a better solution if you have one):

<plugin>
    <artifactId>kotlin-maven-plugin</artifactId>
    <groupId>org.jetbrains.kotlin</groupId>
    <version>${kotlin.version}</version>

    <executions>
        <execution>
            <id>compile</id>
            <phase>process-sources</phase>
            <goals> <goal>compile</goal> </goals>
        </execution>

        <execution>
            <id>test-compile</id>
            <phase>process-test-sources</phase>
            <goals> <goal>test-compile</goal> </goals>
        </execution>
    </executions>
</plugin>

OSGi

For OSGi support see the Kotlin OSGi page.

Examples

An example Maven project can be downloaded directly from the GitHub repository