Skip to content

Getting started

Martin Bonnin edited this page Jul 25, 2023 · 19 revisions

Gettings started with kotlinx.html

Gradle

Groovy

dependencies {
    //Fill this in with the version of kotlinx in use in your project
    def kotlinx_html_version = "your_version_here"

    // include for JVM target
    implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:${kotlinx_html_version}")
	
    // include for JS target
    implementation("org.jetbrains.kotlinx:kotlinx-html-js:${kotlinx_html_version}")

    // include for Common module
    implementation("org.jetbrains.kotlinx:kotlinx-html:${kotlinx_html_version}")
}

Kotlin DSL

dependencies {
    //Fill this in with the version of kotlinx in use in your project
    val kotlinxHtmlVersion = "your_version_here"

    // include for JVM target
    implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:$kotlinxHtmlVersion")

    // include for JS target
    implementation("org.jetbrains.kotlinx:kotlinx-html-js:$kotlinxHtmlVersion")

    // include for Common module
    implementation("org.jetbrains.kotlinx:kotlinx-html:$kotlinxHtmlVersion")
}

Maven

For server-side development you can add the following dependency:

<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-html-jvm</artifactId>
    <version>${kotlinx.html.version}</version>
</dependency>

For client-side (JavaScript) you need this one:

<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-html-js</artifactId>
    <version>${kotlinx.html.version}</version>
</dependency>

If you are building web application with war plugin you can use overlays to pack JavaScripts from webjar like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <dependentWarExcludes>META-INF/*,META-INF/**/*,*meta.js,**/*class</dependentWarExcludes>
        <webXml>src/main/resources/web.xml</webXml>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
            </resource>
        </webResources>
        <overlays>
            <overlay>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-js-library</artifactId>
                <type>jar</type>
                <includes>
                    <include>kotlin.js</include>
                </includes>
                <targetPath>js/</targetPath>
            </overlay>
            <overlay>
                <groupId>org.jetbrains.kotlinx</groupId>
                <artifactId>kotlinx-html-assembly</artifactId>
                <classifier>webjar</classifier>
                <type>jar</type>
                <targetPath>js/</targetPath>
            </overlay>
        </overlays>
    </configuration>
</plugin>

NPM

npm install kotlinx-html

see https://www.npmjs.com/package/kotlinx-html