微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“ mainClassName的设置者:字符串”已弃用 Java中不推荐使用

如何解决“ mainClassName的设置者:字符串”已弃用 Java中不推荐使用

我有一个用Kotlin和Gradle编写的vert.x Web应用程序作为构建工具。该网络应用已使用https://start.vertx.io/生成

build.gradle.kts显示

enter image description here

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")
}

通过什么我应该更换mainClassName

解决方法

执行此操作的最新方法似乎是:

application {
    mainClass.set(launcherClassName)
}
,

在顶层设置mainClassName也应该可以:

mainClassName = "io.vertx.core.Launcher"

https://github.com/AlexeySoshin/KotlinWebDevelopment/blob/20-testing-graphql-api/build.gradle#L14

,

用于 Spring Boot 项目

springBoot {
  mainClass.set("your.full.classname")
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。