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
or build.gradle.kts
file this Kotlin dependency:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-osgi-bundle</artifactId>
<version>${kotlin.version}</version>
</dependency>
---
dependencies {
implementation(kotlin("stdlib"))
implementation("org.jetbrains.kotlin:kotlin-osgi-bundle:$kotlinVersion")
}
---
And some build configurations:
---
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
</build>
----
---
plugins {
kotlin("jvm") version "1.5.10"
}
---
Final Pom.xml 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.3</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> <build> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <goals> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> </plugins> <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> </build> <repositories> <repository> <id>equo-release</id> <name>Equo Public Release Repository</name> <url>https://dl.equo.dev/sdk/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.