Support for getting / injecting shared Maven components in JibMavenPluginExtension
See original GitHub issueI would like to achieve the following in an extension plugin (maybe as a pull request for jib-layer-filter-extension-maven):
- determine the dependencies (including transitive) that come from the parent pom
- put them into one or more separate layers
The idea is that the parent pom defines the “company / project standard” which rarely changes. While the existing jib-layer-filter-extension-maven is already quite useful, it would be still quite cumbersome to write globs for all direct and transitive dependencies. For example, think about having some Spring Boot starters in the parent pom for all your microservice, but some other Spring Boot starters are optional and only used by specific microservices. You not only would need quite exact globs for the Spring Boot starters then, but also for their manyfold transitive dependencies.
So far the introduction…
Now my proposal / request:
For doing advanced tasks like “determine the dependencies (including transitive) that come from the parent pom” in an extension, I need shared Maven components like ProjectDependenciesResolver.
In a Mojo, one would get it like this
@Component
ProjectDependenciesResolver resolver;
But the JibMavenPluginExtension is no Mojo, so I can’t do that.
So far, the following works, but the lookup()
method is already deprecated and will be removed in Maven 4:
ProjectDependenciesResolver resolver = (ProjectDependenciesResolver) mavenData.getMavenSession()
.lookup(org.apache.maven.project.ProjectDependenciesResolver.class.getName());
So do you see any chance to perform dependency injection on the loaded extensions or to provide some other (compatible) way to get shared Maven components?
You can see a first working draft of my approach here https://github.com/stefanocke/jib-extensions/commit/d9652b5a53f763d31469f902804baac171350799
The deprecated lookup()
method is used here https://github.com/stefanocke/jib-extensions/commit/d9652b5a53f763d31469f902804baac171350799#diff-1cf0b87bb4b940a4278b65d96c8da263fc6457a431798f0b1fb7fd2f648c17e6R200
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
@stefanocke thanks for your great contribution! This was really a cool idea, and we were very happy to get help from an expert on this subject.
We released Jib 3.0, and you should be able to start using the feature. (I know I am lazy to update the Jib extensions doc.)
Thanks for your feedback, @chanseokoh. I agree with you that just passing in
ProjectDependenciesResolver
is not a good solution. Regarding Depedency injection in Maven I only know that it was “Plexus container” in former times and it moved to Guice. See https://maven.apache.org/maven-jsr330.htmlHowever, I don’t know enough yet, whether there is any way to apply this DI to our own (non-Mojo) components.
Some hint from someone who is deeper into Maven internals would be helpful. But of course, the solution should be based on some public API of Maven.
If I find out some more details by myself, I will come back here…