找不到 org.jetbrains.kotlinx:kotlinx-html:0.6.4
Posted
技术标签:
【中文标题】找不到 org.jetbrains.kotlinx:kotlinx-html:0.6.4【英文标题】:Could not find org.jetbrains.kotlinx:kotlinx-html:0.6.4 【发布时间】:2018-03-05 18:32:31 【问题描述】:我正在尝试测试 html 应用程序,我的 build.gradle
依赖项是:
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'
运行 gradle build 时出现以下错误:
这里的错误是什么?
【问题讨论】:
【参考方案1】:Here 你可以找到包含 kotlinx 的说明。您需要做的是添加适当的存储库:
repository
jcenter()
和依赖:
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
【讨论】:
谢谢@Opal,你能在这里帮忙吗?请:***.com/questions/46413579/kotlin-html-builder【参考方案2】:感谢@Opal,在他的回答后进一步挖掘,发现我可以使用ktor-html-builder
,所以我的代码变成了这样:
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)
而BlogApp.tk
变成了:
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()
【讨论】:
以上是关于找不到 org.jetbrains.kotlinx:kotlinx-html:0.6.4的主要内容,如果未能解决你的问题,请参考以下文章
关于协程,你知道LifecycleScope吗,超详细解释给你听,真的太香了
Kotlin协程GlobalScope.launch无法引用