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

Searching for mainClass even if entrypoint is specified #4300

Closed
mihalyr opened this issue Aug 27, 2024 · 4 comments
Closed

Searching for mainClass even if entrypoint is specified #4300

mihalyr opened this issue Aug 27, 2024 · 4 comments

Comments

@mihalyr
Copy link

mihalyr commented Aug 27, 2024

Environment:

  • Jib version: 3.4.2
  • Build tool: gradle
  • OS: linux

Description of the issue:

Gradle Jib plugin shows the following warnings when an entrypoint is specified without a main class:

Searching for main class... Add a 'mainClass' configuration to 'jib' to improve build speed.
Could not find a valid main class from 'jar' task; looking into all class files to infer main class.

However, this is wrong, because the mainClass should be ignore when an entrypoint is specified. I'm not sure if this is only cosmetic or Jib indeed searches for a main class that it ignores later, becaue of the entrypoint is already given.

Expected behavior:

No warnings and no searching for main class when an entrypoint is specified.

Steps to reproduce:

  1. configure jib with an entrypoint and no mainclass
  2. run jibDockerBuild

jib-gradle-plugin Configuration:

application {
  mainClass = 'app.Main'
}

jib {
    from {
        image = 'docker://localhost/app-base:latest'
    }
    to {
        image = 'app'
    }
    container {
        appRoot = '/app'
        workingDirectory = '/app'
        entrypoint = ['./run.sh']
        ports = ['8080']
    }
    extraDirectories {
        paths {
            path {
                from = file('bin')
                into = '/app'
                includes = ['run.sh']
            }
        }
        permissions = [
                '/app/run.sh': '755'
        ]
    }
}

Log output:

> Task :app:jibDockerBuild
Caching disabled for task ':app:jibDockerBuild' because:
  Caching has not been enabled for the task
Task ':app:jibDockerBuild' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Searching for main class... Add a 'mainClass' configuration to 'jib' to improve build speed.
Could not find a valid main class from 'jar' task; looking into all class files to infer main class.

Containerizing application to Docker daemon as ...
@chanseokoh
Copy link
Member

chanseokoh commented Sep 1, 2024

This is intended and WAI, because often you want to know the discovered main class in your entrypoint: #4280 (comment).

A simple workaround in your case is to set mainClass to a garbage value.

@mihalyr
Copy link
Author

mihalyr commented Sep 1, 2024

I see, although in my case I do have an application { mainClass = 'app.Main' } configuration. Shouldn't Jib just use that class by default instead of having me to duplicate configuration?

This is intended and WAI, because often you want to know the discovered main class in your entrypoint: #4280 (comment).

If this is indeed the case, I think the warning message might be a bit misleading, since it tells you that the mainClass is ignored, but it is not the case, because setting mainClass will prevent scanning for mainClass and it still generates the files that contain the main class and classpaths, right? So it isn't really ignored, it is just up to you how you utilize the discovered class in your own entrypoint.

mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies are ignored when entrypoint is specified

@chanseokoh
Copy link
Member

Agreed.

@blakeli0
Copy link
Contributor

Thanks @mihalyr for reporting this issue and thanks @chanseokoh for triaging! Closing this as WAI, but we are going look for ways to improve the logging. Feel free to reopen if needed.

@blakeli0 blakeli0 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants