Jib gradle plugin and Java modules?
Environment:
- Jib version:3.4.3
- Build tool: Gradle 8.8
- OS: MacOS Java 22.0.1
Description of the issue:
- How do prevent Jib gradle plugin from using/searching main class and instead make it use main module?
- How do I tell Jib gradle plugin to use module path?
- 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.
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:
- Jib insisting on container.mainClass, or trying to inspect my jars (with ASM) if I do not provide one.
- Jib putting the main module in /app/classpath separate from /app/libs, but this is not a big deal.
- Generating jib-classpath-file and jib-main-class-file, which I do not use.
UPDATE: actually, searching for mainClass even when setting entrypoint is WAI. See https://github.com/GoogleContainerTools/jib/issues/4280#issuecomment-2323346289.
~~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~~
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
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.
Please note our updated contributing policy. We are primarily focused on critical bug fixes and platform evolution to ensure it continues to work for its supported use cases. Closing as WAI