Ошибка в указании MainClassName на kotlin со сборкой Gradle
Всем привет, получаю такую ошибку "A problem was found with the configuration of task ':shadowJar' (type 'ShadowJar').
In plugin 'com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin' type 'com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar' property 'mainClassName' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
- Assign a value to 'mainClassName'.
- Mark property 'mainClassName' as optional." вот мой код
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlinx.serialization)
id("com.github.johnrengelman.shadow")
application
}
application {
mainClass.set("ApplicationKt") // Укажите правильный пакет и имя класса
}
repositories {
mavenCentral()
}
dependencies {
implementation(libs.io.ktor.server.core)
implementation(libs.io.ktor.server.netty)
implementation(libs.io.ktor.serialization.kotlinx.json)
implementation(libs.io.ktor.server.content.negotiation)
implementation(libs.exposed.core)
implementation(project(":database"))
// Test implementation
testImplementation("io.ktor:ktor-server-test-host:3.0.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.21")
testImplementation("io.ktor:ktor-client-mock:3.0.2")
testImplementation("com.h2database:h2:2.3.232")
}
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
manifest {
attributes(
"Main-Class" to application.mainClass.get()
)
}
}
что только не перепробовал, идет 4 день как я пытаюсь решить эту проблему, помогите пожалуйста
Ответы (1 шт):
Автор решения: Влад Глушко
→ Ссылка
Не нужен tasks.withType<>
, нужно написать так
tasks {
shadowJar {
archiveFileName.set("yourJar.jar")
mergeServiceFiles()
manifest {
attributes["Main-Class"] = "ru.devgor.example.MainKt"
}
}
}