Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework main class finding #2457

Merged
merged 4 commits into from
May 7, 2020
Merged

Conversation

chanseokoh
Copy link
Member

@chanseokoh chanseokoh commented May 7, 2020

Fixes #2456.

The logic has changed:

  1. main class explicitly configured (via jib.container.mainClass) but invalid

    • before: attempted to infer a main class under src/.
      • problems and weirdness:
        • never looked into mainClassFromJar despite checking src/ (inconsistency)
        • configured jib.container.mainClass ignored if a valid main is found under `src/', no warning at all
    • after: error
  2. main class not configured, invalid mainClassFromJar, and no or multiple mains found under src/ (i.e., the only main class we could ever get is from the jar-plugin)

    • before: warned mainClassFromJar is invalid, but proceeded with it (this mainClassFromJar used to be called "backup" in our tests)
    • after: error

So, the case in #2456 falls into 2) with multiple mains, and now Jib will fail while printing

[WARNING] 'mainClass' configured in 'maven-jar-plugin' is not a valid Java class: ${start-class}

and

[ERROR] ... Multiple valid main classes were found: hello.Application, hello.Foo, perhaps you should add a 'mainClass' configuration to jib-maven-plugin

As usual, if only one (valid) main is found under src/ while mainClassFromJar is invalid, Jib will continue to use the inferred one rather than mainClassFromJar.

* @return {@code true} if {@code className} is a valid Java class name; {@code false} otherwise
*/
@VisibleForTesting
static boolean isValidJavaClass(String className) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is not a new method; nothing changed.

@chanseokoh
Copy link
Member Author

Oh, forgot CHANGELOG. Will add.

@chanseokoh
Copy link
Member Author

Merging. Feel free to update CHANGELOG afterwards if that doesn't read natural.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jib infers wrong main class if multiple main classes exist
3 participants