-
Create new java project with maven
- replace DgroupId and -DartifactId
mvn archetype:generate -DgroupId=com.playground -DartifactId=KotlinPlayground -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
-
Add kotlin dependencies to pom.xml
modify the pom.xml file to add the kotlin dependencies look at the pom.xml file in this project for reference
-
Create App.kt
package com.playground class Sample() { fun sum(a: Int, b: Int): Int { return a + b } } fun main(args : Array<String>) { println("Hello, World!") }
-
Compile and run
mvn compile exec:java
-
Create test
package com.playground; import kotlin.test.Test import kotlin.test.assertEquals internal class SampleTest { private val testSample: Sample = Sample() @Test fun testSum() { val expected = 42 assertEquals(expected, testSample.sum(40, 2)) } }
-
Pass Custom Command line arguments
mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"]