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 gradle plugin and Java modules? #4280

Open
hrstoyanov opened this issue Jul 2, 2024 · 4 comments
Open

Jib gradle plugin and Java modules? #4280

hrstoyanov opened this issue Jul 2, 2024 · 4 comments

Comments

@hrstoyanov
Copy link

hrstoyanov commented Jul 2, 2024

Environment:

  • Jib version:3.4.3
  • Build tool: Gradle 8.8
  • OS: MacOS Java 22.0.1

Description of the issue:

  1. How do prevent Jib gradle plugin from using/searching main class and instead make it use main module?
  2. How do I tell Jib gradle plugin to use module path?
  3. How do I tell it to stop extracting the content of the jar that has a my main class?

I would like to specify all of these mylsef:

java --module my.module/my.package.App. --module-path /app/libs

I have used the below configuration, but this plugin still tries to infer main class and unzip the jar with the main class.

container{
        entrypoint = [
                "java",
                '--module-path', '/app/libs',
                '--module', 'my.module/my.App'
        ]
    }

Expected behavior:

I want Jib to stop doing so opinionated and classpath-centric, and allow me to set up main module path and main module myself.

@hrstoyanov
Copy link
Author

hrstoyanov commented Jul 2, 2024

Ok, so I start using containerizedMode packed:

    containerizingMode = 'packaged'
    container{
        entrypoint = [
                "java",
                '--module-path', '/app/classpath:/app/libs',
                '--module', 'my.module/my.App'
        ]
        mainClass = 'NotNeeded'
    }

and that seem to prevent Jib from unpacking the main module. I was able to run my app as a 100% modular app, no classpaths involved. Still unhappy about:

  1. Jib insisting on container.mainClass, or trying to inspect my jars (with ASM) if I do not provide one.
  2. Jib putting the main module in /app/classpath separate from /app/libs, but this is not a big deal.
  3. Generating jib-classpath-file and jib-main-class-file, which I do not use.

@chanseokoh
Copy link
Member

chanseokoh commented Jul 2, 2024

UPDATE: actually, searching for mainClass even when setting entrypoint is WAI. See #4280 (comment).

Not ignoring mainClass when setting entrypoint seems like a regression or a bug, because it's not going to be used anyway.

https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#container-object

@hrstoyanov
Copy link
Author

Regression confirmed - commenting out the mainClass below triggers main class discovery:

jib {
    containerizingMode = 'packaged'
    container {
        entrypoint = [
                "java",
                '--module-path', '/app/classpath:/app/libs', 
                '--module', 'my.module/my.App'
        ]
        //mainClass = 'NotNeeded'
    }
}
Execution failed for task ':webapp:jib'.
> Check the full stace trace, and if the root cause is from ASM ClassReader about unsupported class file version, see https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#i-am-seeing-unsupported-class-file-major-version-when-building

@chanseokoh
Copy link
Member

Actually, it's WAI that Jib searches for a main class even if you set a custom entrypoint. Jib still needs to know the main class to generate the /app/jib-main-class-file to support the popular use-case where the user wants to know and use the main class that Jib has found in their custom entrypoint. But I agree this isn't ideal for the Java module use-case.

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

3 participants