Software Development

Kotlin – How to use your Kotlin library in Java Maven projects

This post demonstrates how to use a Maven dependency written in Kotlin in a Java Maven project.

Kotlin Maven Project

Previously, we created a Maven project that only contains Kotlin codes. Please go through the post before reading further.

[wp_ad_camp_1]

Kotlin – How to create Maven project for Kotlin

Maven Dependency to use

We now update our pom.xml to include a Maven dependency to this jar.

[wp_ad_camp_2]

Where’s the Kotlin Runtime Maven dependency?

Somehow the Kotlin library we created included its pom.xml within the jar file.

[wp_ad_camp_3]

The pom.xml already contains the Maven dependency to the Kotlin runtime library.

Using the library

The class name “HelloKt” is based on “Hello.tk” from the Kotlin Maven project.

[wp_ad_camp_4]

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