GoogleContainerTools/jib · warning

'mainClass' configured in ${jarPluginName} is not a valid Ja

Error message

'mainClass' configured in ${jarPluginName} is not a valid Java class: ${mainClass}

What it means

Jib warns that the mainClass property configured in the JAR plugin (maven-jar-plugin or similar) is not a valid Java class name. The plugin validates the class name shape (and optionally that the class exists) before using it; if invalid, it falls back to other mainClass sources and emits this warning.

Source

Thrown at jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java:78

                  + " is not a valid Java class: "
                  + configuredMainClass,
              projectProperties.getPluginName()));
    }

    projectProperties.log(
        LogEvent.info(
            "Searching for main class... Add a 'mainClass' configuration to '"
                + projectProperties.getPluginName()
                + "' to improve build speed."));

    String mainClassFromJarPlugin = projectProperties.getMainClassFromJarPlugin();
    if (mainClassFromJarPlugin != null && isValidJavaClass(mainClassFromJarPlugin)) {
      return mainClassFromJarPlugin;
    }

    if (mainClassFromJarPlugin != null) {
      projectProperties.log(
          LogEvent.warn(
              "'mainClass' configured in "
                  + projectProperties.getJarPluginName()
                  + " is not a valid Java class: "
                  + mainClassFromJarPlugin));
    }
    projectProperties.log(
        LogEvent.info(
            "Could not find a valid main class from "
                + projectProperties.getJarPluginName()
                + "; looking into all class files to infer main class."));

    MainClassFinder.Result mainClassFinderResult =
        MainClassFinder.find(projectProperties.getClassFiles(), projectProperties::log);
    switch (mainClassFinderResult.getType()) {
      case MAIN_CLASS_FOUND:
        return mainClassFinderResult.getFoundMainClass();

      case MAIN_CLASS_NOT_FOUND:

View on GitHub (pinned to fb949e2676)

Solutions

  1. Set mainClass directly in the Jib plugin configuration (jib.mainClass in Maven or jib.mainClass in Gradle) with a fully qualified valid class name
  2. Fix the mainClass value in the jar plugin configuration so it is a valid, existing Java class (e.g. com.example.Main)
  3. Remove the invalid mainClass from the jar plugin configuration if Jib should infer or use another source
  4. Run with debug/verbose logging to see which mainClass Jib ultimately resolved

Example fix

// before (pom.xml)
<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration><archive><manifest><mainClass>com.exmaple.Main</mainClass></manifest></archive></configuration>
</plugin>
// after
<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <configuration><mainClass>com.example.Main</mainClass></configuration>
</plugin>
Defensive patterns

Strategy: validation

Validate before calling

String mc = jarPluginMainClass;
if (mc == null || !mc.matches("[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)*")) {
  throw new IllegalArgumentException("Invalid mainClass in jar plugin config: " + mc);
}

Type guard

boolean isValidJavaClass(String name) {
  return name != null && name.matches("[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)*");
}

Prevention

When it happens

Trigger: The mainClass element in the jar plugin configuration (e.g. maven-jar-plugin's archive manifest mainClass) is empty, misspelled, does not look like a valid class name (no valid Java identifier segments), or points to a class that cannot be resolved.

Common situations: Typo in the package/class name in pom.xml; class removed after refactoring; setting mainClass in the jar plugin instead of the Jib plugin configuration; using a non-class value like a script name.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/1222a0de282d29dd. Report an issue: GitHub.