2

我想要:

  • 里面有.kts文件的目录
  • 带类的经典src/main/kotlin/my/package模块

并有如下用法:

kotlin my-script.main.kts

示例中的脚本如下my-script.main.kts所示

#!/usr/bin/env kotlin

@file:Repository("https://jcenter.bintray.com")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.11")

import kotlinx.html.*; import kotlinx.html.stream.*; import kotlinx.html.attributes.*;
import my.package.*;

val addressee = args.firstOrNull() ?: "World"

print(createHTML().html {
    body {
        h1 { +"Hello, $addressee! from ${my.package.Greater.hello()}" }
    }
})


限制:

  • 没有 jar 依赖项,首先将 jar 发布到 maven repo 然后运行脚本
  • 干净的设计,它应该是可扩展的,而不是 hello world 项目

如何配置依赖于当前模块的 kotlin 脚本项目?迄今为止的最佳实践是什么?

4

0 回答 0