我正在使用Gradle 5.5。我有一个基于Groovy的构建脚本,我正在尝试将其迁移到KotlinDSL。jar
任务包含将所有依赖项复制到SQL文件的典型行:
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
字符串
我找不到一种方法将这行代码转换为KotlinDSL。
让我给予你一些上下文。这是我最初的基于Groovy的构建脚本:
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.41"
}
group = "com.rhubarb_lip_sync"
version = "1.0.0"
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "com.beust:klaxon:5.0.1"
compile "org.apache.commons:commons-lang3:3.9"
compile "no.tornado:tornadofx:1.7.19"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
jar {
manifest {
attributes "Main-Class": "com.rhubarb_lip_sync.rhubarb_for_spine.MainKt"
}
// This line of code recursively collects and copies all of a project"s files
// and adds them to the JAR itself. One can extend this task, to skip certain
// files or particular types at will
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
型
这是我基于Kotlin的构建脚本。它运行得很好,除了那一行:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.41"
}
group = "com.rhubarb_lip_sync"
version = "1.0.0"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("com.beust:klaxon:5.0.1")
implementation("org.apache.commons:commons-lang3:3.9")
implementation("no.tornado:tornadofx:1.7.19")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.withType<Jar> {
manifest {
attributes("Main-Class" to "com.rhubarb_lip_sync.rhubarb_for_spine.MainKt")
}
// ?
}
型
2条答案
按热度按时间emeijp431#
groovy中的
collect()
是Kotlin中的map()
。groovy的三元运算符可以在Kotlin中转换为
if
。主要的区别是,Kotlin中的configurations.compile不是
Configuration
,而是Provider<Configuration>
。因此,要么您将配置从Provider中删除,要么您通过map
将Provider ping到另一个Provider来保持懒惰。所以我认为它应该工作。字符串
或
型
请注意,
compile
已经被弃用很长时间了。由于现在使用implementation
来声明依赖项,编译配置中不再有任何内容,您必须从compileClasspath
中获取依赖项才能构建uber jar。hgtggwj02#
这是一个伟大的样本由Maksim Kostromin
字符串