Gradle Application Plugin Main Class Not Recognized
See original GitHub issueDescription 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:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
That said, we should understand why we cannot infer it for Kotlin.
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.