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]
- Java 8 – JDK
- Windows 10
- IntelliJ IDEA Ultimate 2016
- We may use the Community Edition version of the IDE
- Kotlin version 1.1
Create Maven Project with IntelliJ
1. Create a New Project
Choose File -> Project...
The from the New Project
window, choose Maven
, Create 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 to1.1.2-2
- Update
artifactId
forgroupId
org.jetbrains.kotlin
tokotlin-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
.
1 2 3 4 5 | package com.turreta.maven.kotlin fun sayHello() { println("Hello, World") } |
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