Software Development

Kotlin – How to create Maven project for Kotlin

This post demonstrates how to create a Maven project for Kotlin as as library jar. Instead of a Java codes, we’ll only have Kotlin codes.

Software Requirements

Here is a list of Software applications used for this post.

[wp_ad_camp_1]

  1. Java 8 – JDK
  2. Windows 10
  3. IntelliJ IDEA Ultimate 2016
    • We may use the Community Edition version of the IDE
  4. Kotlin version 1.1

Create Maven Project with IntelliJ

1. Create a New Project

Choose File -> Project...

The from the New Project window, choose MavenCreate from archetype, and org.jetbrains.kotlin:kotlin-archetype-jvm.

[wp_ad_camp_2]

Click Next.

Provide other details for the new project.

Then, click Next.

[wp_ad_camp_3]

Then, click Next.

Then, click Finish.

Update pom.xml

The auto-generated pom.xml create by the IDE needs to be updated.

[wp_ad_camp_4]

  • Update kotlin.version property to 1.1.2-2
  • Update artifactId for groupId org.jetbrains.kotlin to kotlin-stdlib-jre8

Save the changes.

Reimport All Maven Project

After updating the pom.xml, we need to reimport all Maven projects.

Execute Maven Goal

Then we execute Maven install goal.

Type in install and click Execute.

Then, build complete!

Here are the jar and other files generated.

[wp_ad_camp_5]

Update Hello.kt

Update Hello.kt so that we can call a method on it (as part of a jar file – maven dependency) from another Maven project that is written in Java.

Download the codes

The codes are available at

https://github.com/Turreta/Kotlin-How-to-create-Kotlin-Maven-project/blob/master/README.md

References

https://kotlinlang.org/docs/reference/using-maven.html

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like