How to write an Equo app with Kotlin

An Equo app created with the CLI can be easily converted to Kotlin with the following changes.

Changes in pom.xml

First, you need to add into the pom.xml file this Kotlin dependency:

<dependency>
	<groupId>org.jetbrains.kotlin</groupId>
	<artifactId>kotlin-osgi-bundle</artifactId>
	<version>${kotlin.version}</version>
</dependency>

Pom example:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>kotlinapp</groupId>
	<artifactId>kotlinapp</artifactId>
	<version>1.0.0-SNAPSHOT</version>

	<properties>
		<equo.version>1.1.1</equo.version>
		<kotlin.version>1.5.21</kotlin.version>
		<maven.compiler.source>11</maven.compiler.source>
		<maven.compiler.target>11</maven.compiler.target>
	</properties>

	<dependencies>
		<dependency>
			<groupId>com.equo</groupId>
			<artifactId>com.equo.starter.bom</artifactId>
			<version>${equo.version}</version>
		</dependency>
		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-osgi-bundle</artifactId>
			<version>${kotlin.version}</version>
		</dependency>
	</dependencies>

	<repositories>
		<repository>
			<id>equo-release</id>
			<name>Equo Public Release Repository</name>
			<url>https://dl.equoplatform.com/framework/mvn/release</url>
		</repository>
	</repositories>
</project>

Kotlin Equo app

Next, you need to write the main application. You can use tools like the IntelliJ IDE to convert the Java file present in the default app or you can write it by your own.

A basic app should look like this:

fun main(args: Array<String>) {
	EquoApp.launch()
}

@Component
class KotlinAppApplication : IEquoApplication {
	override fun buildApp(appBuilder: EquoApplicationBuilder): EquoApplicationBuilder {
		return appBuilder
			.withUI("index.html")
			.start()
	}
}

And that’s it. Now you can run your Equo app as a Kotlin app.

Example app

Download the example app of this guide to quickly try it out.