如何导入Kotlin(Gradle)版本的ShadowJar插件? [英] how to import the ShadowJar plugin for Kotlin (Gradle) builds?
本文介绍了如何导入Kotlin(Gradle)版本的ShadowJar插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
构建失败:
thufir@dur:~/NetBeansProjects/kotlin_dsl$
thufir@dur:~/NetBeansProjects/kotlin_dsl$ gradle clean run
> Configure project :
e: /home/thufir/NetBeansProjects/kotlin_dsl/build.gradle.kts:4:12: Unresolved reference: github
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'kotlin_dsl'.
> Could not open cache directory 74ykawxta6db3b2bfk9grjikp (/home/thufir/.gradle/caches/4.3.1/gradle-kotlin-dsl/74ykawxta6db3b2bfk9grjikp).
> Internal error: unable to compile script, see log for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
thufir@dur:~/NetBeansProjects/kotlin_dsl$
有问题的导入语句:
thufir@dur:~/NetBeansProjects/kotlin_dsl$
thufir@dur:~/NetBeansProjects/kotlin_dsl$ cat build.gradle.kts
import org.gradle.api.JavaVersion
import org.gradle.kotlin.dsl.*
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
application
kotlin("jvm") version "1.1.51"
}
application {
mainClassName = "samples.HelloWorldKt"
}
dependencies {
compile(kotlin("stdlib"))
}
repositories {
jcenter()
}
thufir@dur:~/NetBeansProjects/kotlin_dsl$
删除如所描述的对Shadow的导入,可以进行干净的构建并运行. Shadow插件JAR如何使Kotlin可以导入?
removing the import for Shadow as described gives a clean build and run. How is the Shadow plugin JAR made available for Kotlin to import?
Gradle本身使用DSL可以创建Shadow JAR.
从另一个角度来看:
科特林遇到Gradle:与ShadowJar一起gradle.build.kt
带有有效的构建文件.
推荐答案
像这样:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm") version "1.2.51"
id("com.github.johnrengelman.shadow") version "2.0.4"
}
group = "xxx.yyy"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.withType<ShadowJar> {
baseName = "app"
classifier = ""
version = ""
}
这篇关于如何导入Kotlin(Gradle)版本的ShadowJar插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文