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

Jib infers wrong main class if multiple main classes exist #2456

Closed
chanseokoh opened this issue May 6, 2020 · 4 comments · Fixed by #2457
Closed

Jib infers wrong main class if multiple main classes exist #2456

chanseokoh opened this issue May 6, 2020 · 4 comments · Fixed by #2457
Milestone

Comments

@chanseokoh
Copy link
Member

chanseokoh commented May 6, 2020

We got a report that Jib uses the string ${start-class) when there are multiple public static void main() defined. I was able to reproduce this on a Spring Boot project. I think the string ${start-class) comes from Spring Boot.

$ cd examples/spring-boot
$ mvn help:effective-pom | grep start-class
                <mainClass>${start-class}</mainClass>
            <mainClass>${start-class}</mainClass>
                <mainClass>${start-class}</mainClass>
                    <mainClass>${start-class}</mainClass>
                <mainClass>${start-class}</mainClass>
            <mainClass>${start-class}</mainClass>
                  <mainClass>${start-class}</mainClass>
              <mainClass>${start-class}</mainClass>

We are supposed to fail and show an error if there are multiple main classes, but seems like this isn't working.

A workaround is to explicitly set the main class with <container><mainClass>.

UPDATE: found a related issue #170

@reechar-goog @saturnism

@chanseokoh chanseokoh added this to the v2.3.0 milestone May 6, 2020
@chanseokoh
Copy link
Member Author

[WARNING] 'mainClass' is not a valid Java class : ${start-class}
...
[INFO] Container entrypoint set to [java, -cp, /app/resources:/app/classes:/app/libs/*, ${start-class}]

@chanseokoh
Copy link
Member Author

I don't know how exactly Spring Boot determines a main class, but having a single @SpringBootApplication does help. If there is no @SpringBootApplication or multiple @SpringBootApplication annotations, then Spring Boot shows an error:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.6.RELEASE:run (default-cli) on project spring-boot-k8s-example: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.1.6.RELEASE:run failed: Unable to find a single main class from the following candidates [hello.Foo, hello.Application] -> [Help 1]

And there seem many other ways Spring Boot determines the main class.

For now, I think we should fix this bug and show an error that multiple main classes are detected.

@chanseokoh
Copy link
Member Author

@reechar-goog @saturnism Jib 2.3.0 is released with the fix.

@saturnism
Copy link

Neat. Thank you!

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

Successfully merging a pull request may close this issue.

2 participants