gpt4 book ai didi

gradle - 如何为 Kotlin (Gradle) 构建导入 ShadowJar 插件?

转载 作者:行者123 更新时间:2023-12-02 12:16:58 30 4
gpt4 key购买 nike

构建失败:

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$

移除 the import for Shadow as described提供干净的构建和运行。如何让 Kotlin 导入 Shadow 插件 JAR?

Gradle 本身使用 DSL,创建了 Shadow JAR 的罚款。

换个角度来看这个:

Kotlin meets Gradle: gradle.build.kt with ShadowJar

带有工作构建文件。

最佳答案

像这样:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("jvm") version "1.5.21"
id("com.github.johnrengelman.shadow") version "7.0.0"
}

group = "xxx.yyy"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}

tasks.withType<ShadowJar> {
archiveFileName.set("app.jar")
}

关于gradle - 如何为 Kotlin (Gradle) 构建导入 ShadowJar 插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48659849/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com