question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gradle Application Plugin Main Class Not Recognized

See original GitHub issue

Description of the issue: I’m using the Gradle application plugin and setting the main class for that:

application {
    mainClassName = "WebAppKt"
}

But the jib plugin is not picking up that setting:

com.google.cloud.tools.jib.plugins.common.MainClassInferenceException: Main class was not found, perhaps you should add a `mainClass` configuration to jib

Expected behavior: The main class should be picked up for jib if set for the application plugin.

Steps to reproduce: Create a build.gradle.kts with:

plugins {
    java
    application
    kotlin("jvm") version "1.3.20"
    id("kotlinx-serialization") version "1.3.20"
    id("com.google.cloud.tools.jib") version "1.0.0"
    id("com.github.johnrengelman.shadow") version "4.0.4"
}

repositories {
    mavenLocal()
    mavenCentral()
    maven("https://kotlin.bintray.com/kotlinx")
}

dependencies {
    compile("io.ktor:ktor-server-core:1.1.3")
    compile("io.ktor:ktor-server-netty:1.1.3")
    compile("io.ktor:ktor-freemarker:1.1.3")
    compile("io.ktor:ktor-client-cio:1.1.3")
    compile("io.ktor:ktor-client-json-jvm:1.1.3")
    compile("ch.qos.logback:logback-classic:1.2.3")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
}

tasks.compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClassName = "WebAppKt"
}

jib {
    val projectId: String? by project
    to.image = "gcr.io/$projectId/where-am-i"
}

Run with the latest gradle.

Environment: Linux

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
chanseokohcommented, Feb 21, 2019

Hi @jamesward,

IIRC, Jib is not able to automatically infer a main class in Kotlin (but I need to double-check that). I’m sure setting it explicitly will work.

jib {
  ...
  container.mainClass = "WebAppKt"
}

That said, we should understand why we cannot infer it for Kotlin.

0reactions
chanseokohcommented, Feb 22, 2019

The auto-detection is fixed in 1.0.1 (by #1457), and #1503 is opened for reusing the application plugin’s settings. I’ll close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle - Could not find or load main class - Stack Overflow
I see two problems here, one with sourceSet another with mainClassName . Either move java source files to src/main/java instead of just src...
Read more >
Error: Could not find or load main class - Gradle Forums
Main class could not be found when there is typo or wrong syntax in the fully qualified java class name or it does...
Read more >
Could Not Find or Load Main Class Error | Java - StackChief
The "Could not find or load main class" error is common and easy to fix. Its cause usually has to do with specifying...
Read more >
Run a Java main Method Using Gradle - Baeldung
plugins { id "application" } apply plugin : "java" ext { javaMainClass = "com.baeldung.gradle.exec.MainClass" } application { mainClassName ...
Read more >
3 ways to solve Eclipse - main class not found error - Java67
The problem in my case was that my project also needed native libraries and due to other errors, I have been fiddling with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found