';mainClassName的setter:String';不推荐使用。在Java中已弃用

';mainClassName的setter:String';不推荐使用。在Java中已弃用,java,kotlin,gradle,vert.x,Java,Kotlin,Gradle,Vert.x,我有一个用Kotlin和Gradle编写的vert.x web应用程序作为构建工具。已使用生成web应用程序 在build.gradle.kts中显示: mainClassName已被弃用 build.gradle.kts文件的内容: import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.api.tasks.testing.logging.TestLogEvent.* import

我有一个用Kotlin和Gradle编写的vert.x web应用程序作为构建工具。已使用生成web应用程序

build.gradle.kts
中显示:

mainClassName
已被弃用

build.gradle.kts
文件的内容:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
  kotlin ("jvm") version "1.4.10"
  application
  id("com.github.johnrengelman.shadow") version "5.2.0"
  id("org.flywaydb.flyway") version "7.1.1"
}

group = "io.databaker"
version = "1.0.0-SNAPSHOT"

repositories {
  mavenCentral()
  jcenter()
}

val kotlinVersion = "1.4.10"
val vertxVersion = "4.0.0.CR1"
val junitJupiterVersion = "5.6.0"

val mainVerticleName = "io.databaker.MainVerticle"
val watchForChange = "src/**/*"
val doOnChange = "./gradlew classes"
val launcherClassName = "io.vertx.core.Launcher"

application {
  mainClassName = launcherClassName
}

dependencies {
  implementation("io.vertx:vertx-auth-jwt:$vertxVersion")
  implementation("io.vertx:vertx-web:$vertxVersion")
  implementation("io.vertx:vertx-pg-client:$vertxVersion")
  implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion")
  implementation("io.vertx:vertx-json-schema:$vertxVersion")
  implementation("io.vertx:vertx-lang-kotlin:$vertxVersion")
  implementation(kotlin("stdlib-jdk8"))
  testImplementation("io.vertx:vertx-junit5:$vertxVersion")
  testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
}

  val compileKotlin: KotlinCompile by tasks
  compileKotlin.kotlinOptions.jvmTarget = "11"

tasks.withType<ShadowJar> {
  archiveClassifier.set("fat")
  manifest {
    attributes(mapOf("Main-Verticle" to mainVerticleName))
  }
  mergeServiceFiles {
    include("META-INF/services/io.vertx.core.spi.VerticleFactory")
  }
}

tasks.withType<Test> {
  useJUnitPlatform()
  testLogging {
    events = setOf(PASSED, SKIPPED, FAILED)
  }
}

tasks.withType<JavaExec> {
  args = listOf("run", mainVerticleName, "--redeploy=$watchForChange", "--launcher-class=$launcherClassName", "--on-redeploy=$doOnChange")
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
导入org.gradle.api.tasks.testing.logging.TestLogEvent*
导入org.jetbrains.kotlin.gradle.tasks.KotlinCompile
插件{
kotlin(“jvm”)版本“1.4.10”
应用
id(“com.github.johnrengelman.shadow”)版本“5.2.0”
id(“org.flywaydb.flyway”)版本“7.1.1”
}
group=“io.databaker”
version=“1.0.0-SNAPSHOT”
存储库{
mavenCentral()
jcenter()
}
val kotlinVersion=“1.4.10”
val vertxVersion=“4.0.0.CR1”
val junitJupiterVersion=“5.6.0”
val mainVerticleName=“io.databaker.MainVerticle”
val watchForChange=“src/***”
val doOnChange=“./gradlew类”
val launcheClassName=“io.vertx.core.Launcher”
应用{
mainClassName=launcherClassName
}
依赖关系{
实现(“io.vertx:vertx auth jwt:$vertxVersion”)
实现(“io.vertx:vertxweb:$vertxVersion”)
实现(“io.vertx:vertx pg客户端:$vertxVersion”)
实现(“io.vertx:vertx-lang-kotlin协同程序:$vertxVersion”)
实现(“io.vertx:vertxjson模式:$vertxVersion”)
实现(“io.vertx:vertx-lang-kotlin:$vertxVersion”)
实施(kotlin(“stdlib-jdk8”))
测试实现(“io.vertx:vertx-junit5:$vertxVersion”)
测试实现(“org.junit.jupiter:junitjupiter:$junitJupiterVersion”)
}
val compileKotlin:kotluncompileby tasks
compileKotlin.kotlinOptions.jvmTarget=“11”
tasks.withType{
archiveClassifier.set(“fat”)
显示{
属性(mapOf(“mainverticle”到mainVerticleName))
}
合并服务文件{
包括(“META-INF/services/io.vertx.core.spi.VerticleFactory”)
}
}
tasks.withType{
useJUnitPlatform()
测试记录{
事件=集合(通过、跳过、失败)
}
}
tasks.withType{
args=listOf(“run”,mainVerticleName,“--redeploy=$watchForChange”,“--launcher class=$launcherClassName”,“--on redeploy=$doOnChange”)
}

通过什么替换
mainClassName

最新的方法似乎是:

application {
    mainClass.set(launcherClassName)
}

在顶层设置
mainClassName
也可以:

mainClassName=“io.vertx.core.Launcher”

用于spring boot项目

springBoot{
mainClass.set(“您的.full.classname”)
}

您的示例不在
build.gradle
文件中,而不是
build.gradle.kts
,在Kotlin构建脚本中不起作用。