question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for getting / injecting shared Maven components in JibMavenPluginExtension

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
chanseokohcommented, Apr 9, 2021

@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.)

1reaction
stefanockecommented, Feb 11, 2021

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.html

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Micronaut Maven Plugin – Project Dependencies
Project Transitive Dependencies. The following is a list of transitive dependencies for this project. Transitive dependencies are the dependencies of the ...
Read more >
Guide to Configuring Plug-ins - Apache Maven
Guide to Configuring Plug-ins. Introduction; Generic Configuration. Help Goal; Configuring Parameters. Mapping Value Objects; Mapping Complex ...
Read more >
Apache Maven Shared Utils – Project Dependencies
Apache Public License 2.0: Plexus Cipher: encryption/decryption Component, Plexus Security Dispatcher Component.
Read more >
Maven & JSR-330
inject dependency and the sisu-maven-plugin configured to create the JSR-330 component index. When you build and place the extension JAR in the ${MAVEN_HOME}/ ......
Read more >
Project Dependencies - Apache Maven Help Plugin
org.apache.maven.shared, maven-shared-utils ... org.codehaus.plexus, plexus-component-annotations ... org.eclipse.sisu, org.eclipse.sisu.inject, 0.3.5 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found