GoogleContainerTools/jib · error · MainClassInferenceException
Multiple valid main classes were found: ${mainClasses}
Error message
Multiple valid main classes were found: ${mainClasses} What it means
MainClassInferenceException thrown by MainClassResolver.resolveMainClass() when MainClassFinder.find() returns MULTIPLE_MAIN_CLASSES: scanning all class files produced more than one class with a valid main method, so Jib cannot choose an entrypoint unambiguously. The message lists the comma-separated candidates (mainClasses). This fires when no mainClass is configured and the classpath contains several runnable mains (e.g. test utilities, tools, legacy entrypoints).
Source
Thrown at jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java:102
case MULTIPLE_MAIN_CLASSES:
throw new MainClassInferenceException(
HelpfulSuggestions.forMainClassNotFound(
"Multiple valid main classes were found: "
+ String.join(", ", mainClassFinderResult.getFoundMainClasses()),
projectProperties.getPluginName()));View on GitHub (pinned to fb949e2676)
Solutions
- Explicitly configure the desired main class so inference is skipped entirely
- Exclude the unwanted main classes from the compiled output, or move helper mains out of the production classes
- Keep only one class with 'public static void main' in the module if auto-detection is desired
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java:102 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/390e755286ea78d4.
Report an issue: GitHub.