-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support for getting / injecting shared Maven components in JibMavenPluginExtension #3036
Comments
Hi @stefanocke, I think this is a very interesting idea. It's just that we are unsure what would be the best architecture to enable this with enough flexibility and expandability. Should Jib just pass What's your thoughts? Any detailed design proposal? BTW, I think we have to leave this as a low priority. Not that we think this is not important, but our resources are very limited at the moment. We also welcome contributions. |
Thanks for your feedback, @chanseokoh. I agree with you that just passing in However, 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... |
Okay, so approximately my plan would be to make the extension a Sisu / Guice / JSR-330 component and to inject it into the jib plugin instead of creating it by using the service loader. Pretty much as the I am not sure yet, if jib has completely move from plexus to Sisu / Guice / JSR-330 then or if it is possible to mix. Sisu / Guice / JSR-330 needs at least Maven 3.1.0. So, jib would not work for older Maven versions. Would this be an issue, @chanseokoh? |
Thanks for looking into it! I think I am not following all the technical stuff you said (😅 hopefully it's easy to implement and doesn't incur a lot of changes). However, At least I can say requiring 3.1.0+ is OK. I see 3.1.0 was released in 2015. |
injection of extensions
@chanseokoh , I have implemented the approach in the commit stefanocke@0c122a1. Basically the solution comes down to inject the extensions into the MOJO like this:
The extension just needs to declare itsfelf as a JSR-330 / Sisu Component by adding the following annotations:
And finally, some index is required in
Under the hoods, Sisu will discover the so declared component and apply dependency injection to it, which allows me to accomplish my original goal to inject shared Maven components into the extension like this:
Could you please have a look? If this approach is okay with you, I would add some integration test and create a pull request. |
Thanks a lot for doing this! We'll get back to this as soon as we have time, but please be patient until then. |
injection of extensions shows how to use dependency injection in an extension
injection of extensions - test
It needed some polishing, but now everything should be ready in the pull request. |
…or dependencies from parent POM (#76) * Moving parent dependencies to separate layers - first draft * Maps of dependencies instead of Sets to support better error handling * GoogleContainerTools/jib#3036 support injection of extensions shows how to use dependency injection in an extension * configuration for createParentLayers And formatting and logging. * some tests * some more tests * googleJavaFormat * Review, first part * Review: fixed all remaining minor issues. Left the more interesting ones still open for further consideration. * getBaseVersion instead of getVersion * match filename instead of complete extraction path to not depend on "app/libs", which is connfigurable in jib * log potential matches when parent dependency not found use source file name for matching instead of filename from extraction path * Use complete source path instead of filename for matching Especially on the Artifact side that means that the filename is not "constructed" anymore by the extension. We make no assumption about the structure of the source file name or path. The only assumption that is left is, that Maven will resolve to the same file path, if the same artifact coordinates are resolved multiple times within a build / session. * Review: some minor issues
…uginExtension (#3062) * #3036 support injection of extensions * #3036 support injection of extensions - test * fix gradle plugin validation error * fix checkstyly * fix checkstyle * fix checkstyle * fix googleJavaFormat * fix googleJavaFormat * fix checkstyle again :-( * increase test coverage * polishing: avoid type casting for extension * reworked: injected extensions should not be part of extension configuration ... but just another extensionLoader mechanism * test coverage * refactoring: pull up getMavenProjectProperties and test it * Revert "refactoring: pull up getMavenProjectProperties" This reverts commit 279418c. * Review
Fixed by #3062. This new approach to load Jib extensions (which enables injecting Maven components) will be documented in the jib-extensions README. |
@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.) |
…eating parent dependency layers in jib-layer-filter-extension-maven (#81) * Documentation for GoogleContainerTools/jib#3036 and #76 * Update README.md Co-authored-by: Chanseok Oh <chanseok@google.com>
I would like to achieve the following in an extension plugin (maybe as a pull request for jib-layer-filter-extension-maven):
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
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: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 stefanocke/jib-extensions@d9652b5
The deprecated
lookup()
method is used here stefanocke/jib-extensions@d9652b5#diff-1cf0b87bb4b940a4278b65d96c8da263fc6457a431798f0b1fb7fd2f648c17e6R200The text was updated successfully, but these errors were encountered: