public static String resolveMainClass(
      @Nullable String configuredMainClass, ProjectProperties projectProperties)
      throws MainClassInferenceException, IOException {
    if (configuredMainClass != null) {
      if (isValidJavaClass(configuredMainClass)) {
        return configuredMainClass;
      }
      throw new MainClassInferenceException(
          HelpfulSuggestions.forMainClassNotFound(
              "'mainClass' configured in "
                  + projectProperties.getPluginName()
                  + " 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:
        throw new MainClassInferenceException(
            HelpfulSuggestions.forMainClassNotFound(
                "Main class was not found", projectProperties.getPluginName()));

      case MULTIPLE_MAIN_CLASSES:
        throw new MainClassInferenceException(
            HelpfulSuggestions.forMainClassNotFound(
                "Multiple valid main classes were found: "
                    + String.join(", ", mainClassFinderResult.getFoundMainClasses()),
                projectProperties.getPluginName()));

      default:
        throw new IllegalStateException("Cannot reach here");
    }
  }
If {@code mainClass} is {@code null}, tries to infer main class in this order:

<ul>
  <li>1. Looks in a {@code jar} plugin provided by {@code projectProperties} ({@code
      maven-jar-plugin} for maven or {@code jar} task for gradle).
  <li>2. Searches for a class defined with a main method.
</ul>

<p>Warns if main class provided by {@code projectProperties} is not valid, or throws an error
if no valid main class is found.

@param configuredMainClass the explicitly configured main class ({@code null} if not
    configured)
@param projectProperties properties containing plugin information and help messages
@return the name of the main class to be used for the container entrypoint
@throws MainClassInferenceException if no valid main class is configured or discovered
@throws IOException if getting the class files from {@code projectProperties} fails
jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/MainClassResolver.java