0

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.

  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.

Click Next.

Provide other details for the new project.

Then, click Next.

Then, click Next.

Then, click Finish.

Update pom.xml

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

  • 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.

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

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert