【问题标题】:'setter for mainClassName: String' is deprecated. Deprecated in Java'setter for mainClassName: String' 已被弃用。在 Java 中已弃用
【发布时间】:2021-02-21 05:56:41
【问题描述】:

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

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

我应该通过什么替换mainClassName

【问题讨论】:

    标签: java kotlin gradle vert.x


    【解决方案1】:

    以下 3 个中的任何一个都应该有效:

    springBoot {
        mainClass.set('package.class')
    }
    
    bootJar {
        mainClass.set('package.class')
    }
    
    application {
        mainClass.set('package.class')
    }
    

    【讨论】:

      【解决方案2】:

      用于春季启动项目

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

      【讨论】:

        【解决方案3】:

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

        mainClassName = "io.vertx.core.Launcher"
        

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

        【讨论】:

        • 您的示例不在 build.gradle 文件中,而不是在 build.gradle.kts 中,并且无法在 Kotlin 构建脚本中使用。
        【解决方案4】:

        看来最新的做法是:

        application {
            mainClass.set(launcherClassName)
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-07-10
          • 1970-01-01
          • 2015-02-03
          • 1970-01-01
          • 1970-01-01
          • 2019-04-04
          • 2018-12-12
          • 2014-09-18
          相关资源
          最近更新 更多