GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.68k stars 1.44k forks source link

Jib creates invalid classpath entries if Maven dependency is of type pom #3736

Open fsimmend opened 2 years ago

fsimmend commented 2 years ago

Environment:

Description of the issue:

Given the setup of a multimodule project, where there are maven modules without code but with dependencies, so that they encapsulate a set of runtime dependencies. Let's call them dependencyaggregators.

If an application module has a dependency with type pom to a sibling project and if the maven process is started at the root of the multimodule project. Jib will package the pom of the dependencyaggregator with an added "jar" extension into the image and into the classpathlist. If the application project is build directly, the pom.xml.jar will not be packaged.

When the application is a spring boot tomcat application, the tomcat classpath scanner will complain, because the pom.xml.jar artifact is no archive that can be scanned.

The issue from my perspective is, that there is no filtering on packaging types that can be put into the classpath. Because we are talking here about artifacts from dependencies, it can only be package type jar, war but it could also be a zip file but that would not be standard maven. As a fix i would propose to filter project.getArtifacts() in the caller of com.google.cloud.tools.jib.maven.MavenProjectProperties#classifyDependencies.

mpeddada1 commented 2 years ago

@fsimmend the Jib Layer Filter Extension is worth looking into. It allows for more fine grained control over the files that are added to your container image. Particularly, if there is a file that would like to delete from the dependencies layer when building your final image, it should allow you to do that:

fsimmend commented 1 year ago

It is possible to exclude the jar from the image but it will not be cleared from the generated jib-classpath-file leading to an ioexception at the start. Since there is only a single maven phase being used, there is no way to remove that entry without using a custom entrypoint to fix the issue.

mlauke commented 1 year ago

@mpeddada1 any updates here? should we provide a patch/PR for that issue?

mpeddada1 commented 7 months ago

Thanks for following up. IIUC, this is a feature request and not a regression in existing support. As described in the CONTRIBUTING.md doc we are currently prioritizing critical bug fixes or platform evolution changes at the moment.

The workaround for now will be to use Jib Layer Filter Extension with a custom entrypoint to support this use case.