Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'setter for mainClassName: String' is deprecated. Deprecated in Java

I have a vert.x web app written in Kotlin and Gradle as the build tool. The web app has been generated with https://start.vertx.io/.

In the build.gradle.kts it shows:

enter image description here

that mainClassName has been deprecated.

the content of the build.gradle.kts file:

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

Through what should I replace the mainClassName?

like image 947
softshipper Avatar asked Nov 09 '20 10:11

softshipper


People also ask

How to deprecate a method or class in Java?

How to Deprecate? We use the @Deprecated annotation to deprecate a method, class, or field, and the @deprecated Javadoc tag in the comment section to inform the developer about the reason for deprecation and what can be used in its place. 1. Deprecated interface:

Is 'setter for mainclassname()' deprecated in Kotlin?

kotlin - 'setter for mainClassName: String' is deprecated. Deprecated in Java - Stack Overflow 'setter for mainClassName: String' is deprecated. Deprecated in Java I have a vert.x web app written in Kotlin and Gradle as the build tool.

What does deprecated mean in Java 9?

@Deprecated indicates to other developers that the marked element should be avoided. With Java 9, two new enhancements are made to @Deprecated annotation: forRemoval: Indicates whether the annotated element is subject to removal in a future version.

How do you know if an element is deprecated in Java?

If a deprecated element is used by some other element that is deprecated. That is, deprecated class calls a deprecated constructor. If the deprecated element is used inside an entity that has an annotation @SuppressWarnings (“deprecation”).


4 Answers

It seems the latest way of doing this is:

application {     mainClass.set(launcherClassName) } 
like image 157
tsegismont Avatar answered Sep 24 '22 07:09

tsegismont


for spring boot project

springBoot {   mainClass.set("your.full.classname") } 
like image 29
Diluka W Avatar answered Sep 20 '22 07:09

Diluka W


Any of the below 3 should work:

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

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

application {
    mainClass.set('package.class')
}
like image 45
Pinkesh Sharma Avatar answered Sep 20 '22 07:09

Pinkesh Sharma


Setting mainClassName on the top level should work too:

mainClassName = "io.vertx.core.Launcher"

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

like image 31
Alexey Soshin Avatar answered Sep 20 '22 07:09

Alexey Soshin