Get Started
Table of contents
- Setup the environment
- Create a new Kotlin project
- Configure the project
- Create your first pipeline
- Run the job
- Inspect the results
- What’s next
Setup the environment
Before starting, you should check your development environment:
- Download and install the Java Development Kit (JDK) version 8. Verify that the
JAVA_HOME
environment variable points to your JDK installation. - Download and install Apache Maven by following Maven’s installation guide.
We recommend using IntelliJ IDEA to just create a new project from the archetype (see the next section). |
Create a new Kotlin project
Use Maven to create a new Kotlin project via the following command:
$ mvn archetype:generate \
-DarchetypeGroupId=org.jetbrains.kotlin \
-DarchetypeArtifactId=kotlin-archetype-jvm \
-DarchetypeVersion=1.3.72 \
-DgroupId=org.example \
-DartifactId=kio-word-count \
-Dversion="0.1" \
-Dpackage=org.example.kio \
-DinteractiveMode=false
This script will create a new directory kio-word-count
with pom.xml
and some other files.
Configure the project
At the next step it’s needed to add the following lines to the pom.xml
file:
- Property for Kotlin compiler to set target JVM version (into the
properties
block):<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
- Dependency description for Kio (into the
dependencies
block):<dependency> <groupId>ru.chermenin.kio</groupId> <artifactId>kio-core</artifactId> <version>x.y.z</version> </dependency>
Create your first pipeline
- Add a new file
WordCount.kt
to the/src/main/kotlin/org/example/kio
directory. - Edit it to define a new
WordCount
object and themain
method:package org.example.kio object WordCount { @JvmStatic fun main(args: Array<String>) { } }
- Create the Kio context:
val kio = Kio.fromArguments(args)
- Read lines from the inputs:
val lines = kio.read().text(kio.arguments.required("input"))
- Split line to words:
val words = lines.flatMap { it.split("\\W+".toRegex()) }
- Filter empty values:
val filtered = words.filter { it.isNotBlank() }
- Count words:
val counts = filtered.countByValue()
- Format the results:
val results = counts.map { "${it.key}: ${it.value}" }
- Write the results to the output:
results.write().text(kio.arguments.required("output"))
- And execute the pipeline:
kio.execute().waitUntilFinish()
Run the job
To execute the job run the command with input
and output
arguments:
$ mvn compile exec:java -Dexec.mainClass=org.example.kio.WordCount \
-Dexec.args="--input=pom.xml --output=counts"
Inspect the results
Once the pipeline has completed, you can view the output in multiple files prefixed by counts
:
$ more counts*
executions: 2
count: 2
scope: 4
main: 1
dependencies: 2
plugins: 2
kotlin: 17
...
What’s next
Learn more about Kio viewing the Developers Guide and feel free to help us with the project.