Skip to content

Support BOM incremental changes #241

Closed

Description

@gastaldi

This may be a crazy idea, but I'd love to see it implemented:

If a BOM is used (a managed dependency with <type>pom</type> and <scope>import</scope>) in a project and a dependency version included in this BOM is changed, it would be nice if GIB could build only the modules that depend on the changed dependency.

Activity

  1. gastaldi commented on Aug 26, 2020

    @gastaldi
    ContributorAuthor

    I think this can be split into two action items:

    • Detect downstream modules on a BOM module (BOMs added in dependencyManagement doesn’t seem to participate in the dependency graph resolution - need to confirm this)
    • Detect the dependencies changed in the BOM and build the downstream modules for those dependencies
  2. added this to the release-3.12.0 milestone on Aug 30, 2020
  3. self-assigned this
    on Aug 30, 2020
  4. famod commented on Aug 30, 2020

    @famod
    Member

    @gastaldi You did not mention this so I think we are on the same page: I will only consider the downstream path, meaning that GIB will not consider the BOM artifact an upstream dependency for all modules it is imported in. Do you agree?

    PS: I might actually have a timeboxed look at this but the downstream path is more important.

  5. gastaldi commented on Aug 30, 2020

    @gastaldi
    ContributorAuthor

    @famod yes, that's correct.

  6. famod commented on Aug 31, 2020

    @famod
    Member

    @gastaldi WDYT: I thought about adding a new property bomArtifactIdRegex (or similar) that can be used to give GIB an optimization hint so that it does not have to treat every pom module as a potential BOM.
    For Quarkus this could be set to quarkus-bom(-test)?.

    You could also use this property to effectively disable the BOM check (e.g. - or some other fake value).

    I am not sure about the default value. Could be disabled (-) by default to avoid an unnecessary performance hit or could be empty but then it would always consider BOMs.
    Or empty means "don't consider BOMs". I actually think this is the best approach. If someone wants GIB to consider BOMs without any hint, then .* can be used (but is discouraged).

  7. gastaldi commented on Aug 31, 2020

    @gastaldi
    ContributorAuthor

    @famod that sounds like a good idea, but isn't easier to just assume that pom packaging-projects with dependencyManagement are BOMs?

  8. famod commented on Aug 31, 2020

    @famod
    Member

    @gastaldi

    but isn't easier to just assume that pom packaging-projects with dependencyManagement are BOMs?

    Easier in terms of amount of code to write: yes.
    But for each found pom module that is changed or dependends on changed modules, I have to consult all projects in the reactor to check whether they import the respective pom module as a BOM. This can quickly become inefficient.

  9. gastaldi commented on Aug 31, 2020

    @gastaldi
    ContributorAuthor

    Yes, and can also inherit from their parent poms too, so maybe we need to think a bit on how would that work performance-wise since having an effective model of each project will definitely be an inefficient operation

  10. famod commented on Aug 31, 2020

    @famod
    Member

    Status: First successful run with Quarkus! A change to quarkus-bom triggers 666 (😮) modules, instead of 690 for non-incremental build. 🎉
    Nasty catch: MavenProject.getDependencyManagement() (for quarkus-build-parent) does not contain the quarkus-bom dependency anymore! Took me some time to realize that I have to use the depMgmt of the "raw" model instead via MavenProject.getOriginalModel().getDependencyManagement().

  11. gastaldi commented on Aug 31, 2020

    @gastaldi
    ContributorAuthor

    Ah I forgot about the getOriginalModel(). This means that the MavenProject itself is already an effective model (which means that #241 (comment) is already resolved).

  12. famod commented on Aug 31, 2020

    @famod
    Member

    And it's rather fast too, even without bomArtifactIdRegex (numbers in nanoseconds):

    [INFO] Changed Artifacts:
    [INFO]
    [INFO] quarkus-bom
    [INFO]
    quarkus-build-parent took 682400
    quarkus-bom took 5118300
    [INFO] gitflow-incremental-builder exiting...
    

    Small annoyance (see last line):

        private boolean isBOMImport(Dependency dependency, MavenProject potentialBOMProject) {
            return "pom".equals(dependency.getType())
                    && "import".equals(dependency.getScope())
                    && dependency.getArtifactId().equals(potentialBOMProject.getArtifactId())
                    && dependency.getGroupId().equals(potentialBOMProject.getGroupId())
                    && (dependency.getVersion().equals(potentialBOMProject.getVersion()) || dependency.getVersion().startsWith("${"));
        }

    In Quarkus it is ${project.version} which I consider best practise but it could also be something else. Might yield false positives though but I don't think it is very common to use a BOM that lives in the same project with another version than the rest...?

    Will create a PR tomorrow or on Wednesday.

  13. gastaldi commented on Aug 31, 2020

    @gastaldi
    ContributorAuthor

    Can't wait to try it :)

  14. famod commented on Aug 31, 2020

    @famod
    Member

    @gastaldi

    * [ ]  Detect the dependencies changed in the BOM and build the downstream modules for those dependencies
    

    I must have overlooked this but I am not sure that I'll be implementing this for 3.12.0 since this is much more than "just" detecting all downstream modules of a BOM.

    I mean GIB would need to:

    • parse the diff
    • match the changed property (or properties) to dependencies or (in case no properties are used) look "around" the changed line for the respective coordinates
    • find all modules that depend on the BOM (mostly done) and depend on one of the changed dependencies
  15. gastaldi commented on Aug 31, 2020

    @gastaldi
    ContributorAuthor

    Yeah, that's why I split into two actions:

    • The first is a minimum requirement to make it work with BOMs;

    • The second one is more fine grained and adds a lot of value if/when implemented. It can be part of a later release if you like

  16. gastaldi commented on Aug 31, 2020

    @gastaldi
    ContributorAuthor

    The second action should also take in account changed transitive dependencies (hence why an effective model is necessary in this case)

    Eg. commons-io is changed in the BOM and the kubernetes extension must be a candidate, because it depends on kubernetes-client, which depends on commons-io transitively.

  17. famod commented on Sep 2, 2020

    @famod
    Member

    PR takes me a little longer since I found a way to resolve something like ${project.version} properly.

    WIP branch: master...famod:issue-241-bom-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions