我不知道如何使用 阴影 使用 kotlin DSL 构建的 gradle 中的插件。
所有文档都使用 groovy dsl。
这是 build.gradle.kts 的内容:
import groovy.lang.GroovyObject
import org.gradle.jvm.tasks.Jar
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.4.10"
id("com.github.johnrengelman.shadow") version "6.1.0"
application
}
allprojects {
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
group = "com.example"
version = "1.0-SNAPSHOT"
}
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}
application {
mainClass.set("com.example.MainKt")
}
tasks.withType<Jar> {
manifest {
attributes(
mapOf(
"ImplementationTitle" to project.name,
"Implementation-Version" to project.version)
)
}
}
这是 src/main/kotlin/com/example/Main.kt
的内容package com.example
fun main() {
println("Hello world")
}
但是当我尝试做 gradle build
,我得到这个错误:A problem was found with the configuration of task ':shadowJar' (type 'ShadowJar').
> No value has been specified for property 'mainClassName'.
我认为这很奇怪,因为我已经在 application
中输入了应用程序主类。争论。我试图添加这个:
tasks.withType<ShadowJar>() {
mainClassName = "com.example.MainKt"
}
但是当我尝试使用此选项进行构建时,它会提示找不到 ShadowJar
类型。 Line 22: tasks.withType<ShadowJar>() {
^ Unresolved reference: ShadowJar
我在这里做错了什么?
最佳答案
问题是我试图添加 mainClassName
到ShadowJar
任务,它应该被添加到 application
功能。像这样:
application {
val name = "com.cognite.ingestionservice.MainKt"
mainClass.set(name)
// Required by ShadowJar.
mainClassName = name
}
mainClassName
属性已弃用,但 ShadowJar 从版本 起仍需要该属性6.1.0 .mainClass.set()
添加 mainClassName
时不需要,但它在 gradle 6.7 的文档中,所以我还是添加了它。
关于kotlin - 如何使用 kotlin dsl 配置 Shadow 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64612654/