Search code examples
springspring-bootgradleheroku

Gradle projet, error NoSuchMethodException during deployment on heroku


i'm trying to deploy a Spring boot project with gradle on heroku.

But during the deployment on Herku when the application tries to launch I get the following error:

2021-08-20T07:22:42.904392+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=42904 $JAVA_OPTS -jar build/libs/api-gateway-0.0.1-SNAPSHOT.jar`
2021-08-20T07:22:44.675657+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-08-20T07:22:44.679643+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-08-20T07:22:44.990415+00:00 app[web.1]: Exception in thread "main" java.lang.NoSuchMethodException: com.abade.apigateway.ApiApplication.main([Ljava.lang.String;)
2021-08-20T07:22:44.990713+00:00 app[web.1]: at java.base/java.lang.Class.getDeclaredMethod(Class.java:2475)
2021-08-20T07:22:44.990742+00:00 app[web.1]: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
2021-08-20T07:22:44.990803+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
2021-08-20T07:22:44.990841+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
2021-08-20T07:22:44.990880+00:00 app[web.1]: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
2021-08-20T07:22:45.062399+00:00 heroku[web.1]: Process exited with status 1

When I don't specify the main class in the gradle and the jar in the Procfile I get an error: no main manifest attribute.

This is my Procfile :

web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/api-gateway-0.0.1-SNAPSHOT.jar

And my build.gradle :

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.5.3"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.4.32"
    kotlin("plugin.spring") version "1.4.32"
}

group = "com.abade"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("com.google.firebase:firebase-admin:8.0.0")
    implementation("junit:junit:4.13.1")
    implementation("org.modelmapper:modelmapper:2.3.3")
    implementation ("io.springfox:springfox-boot-starter:3.0.0")
    runtimeOnly("com.h2database:h2")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("org.mockito:mockito-core:3.+")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "11"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

springBoot {
    mainClass.set("com.abade.apigateway.ApiApplication")
}

Do you have any suggestions ?


Solution

  • It tries to tell you, that com.abade.apigateway.ApiApplication lacks method main([Ljava.lang.String;) ...and therefore the main entry point is unknown.