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]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ... <dependencies> <dependency> <groupId>com.turreta.maven.kotlin</groupId> <artifactId>com-turreta-maven-kotlin</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> ... |
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.
1 2 3 4 5 6 7 8 | import com.turreta.maven.kotlin.HelloKt; public class KotlinLibraryDemo { public static void main(String[] args) { // This was written in Kotlin HelloKt.sayHello(); } } |
[wp_ad_camp_4]
References
https://kotlinlang.org/docs/reference/using-maven.html