Could not find org.jetbrains.kotlinx:kotlinx-html:0.6.4

5.4k views Asked by At

I'm trying to test the HTML Application, my build.gradle dependencies are:

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile "org.jetbrains.ktor:ktor-core:$ktor_version"
    compile 'org.jetbrains.kotlinx:kotlinx-html:0.6.4'
    compile "org.jetbrains.ktor:ktor-netty:$ktor_version"
    compile "org.apache.commons:commons-email:1.4"
    compile "org.slf4j:slf4j-simple:1.7.25"
    compile "ch.qos.logback:logback-classic:1.2.1"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

I got the below error while running gradle build:

Could not find org.jetbrains.kotlinx:kotlinx-html:0.6.4

what is the error here?

2

There are 2 answers

1
Opal On BEST ANSWER

Here you can find instructions on including kotlinx. What you need to do is to add appropriate repository:

repository {
   jcenter()
}

and dependencies:

dependencies {
   compile 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.4' // server side dev
   compile 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.4'  // client side dev 
}
0
Hasan A Yousef On

Thanks to @Opal, digging further after his answer, and found that I can use ktor-html-builder, so my code became this:

gradle.build:

group 'Example'

version 'alpha'

buildscript {
    ext.kotlin_version  = '1.1.4-3'
    ext.ktor_version    = '0.4.0'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'java'
apply plugin: 'kotlin'

sourceCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
    maven { url  "http://dl.bintray.com/kotlin/ktor" }
    maven { url "https://dl.bintray.com/kotlin/kotlinx" }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile "org.jetbrains.ktor:ktor-core:$ktor_version"
    compile "org.jetbrains.ktor:ktor-netty:$ktor_version"
    compile "org.jetbrains.ktor:ktor-html-builder:$ktor_version"

    compile "org.apache.commons:commons-email:1.4"
    compile "org.slf4j:slf4j-simple:1.7.25"
    compile "ch.qos.logback:logback-classic:1.2.1"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
kotlin {
    experimental {
        coroutines "enable"
    }
}


jar {
    baseName 'abc'
    manifest {
        attributes 'Main-Class': 'blog.BlogAppKt'
    }

    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

And the BlogApp.tk became:

package blog

import kotlinx.html.*
import org.jetbrains.ktor.host.*   // for embededServer
import org.jetbrains.ktor.netty.*  // for Netty
import org.jetbrains.ktor.application.*
import org.jetbrains.ktor.features.*
import org.jetbrains.ktor.html.*
import org.jetbrains.ktor.routing.*

fun Application.module() {
    install(DefaultHeaders)
    install(CallLogging)
    install(Routing) {
        get("/") {
            call.respondHtml {
                head {
                    title { +"HTML Application" }
                }
                body {
                    h1 { +"Sample application with HTML builders" }
                    widget {
                        +"Widgets are just functions"
                    }
                }
            }
        }
    }
}

fun FlowContent.widget(body: FlowContent.() -> Unit) {
    div { body() }
}

fun main(args: Array<String>) {
    embeddedServer(Netty, 8080, watchPaths = listOf("BlogAppKt"), module = Application::module).start()
}