2

Can a Maven BOM(BOM1) contain another BOM(BOM2) in its dependencyManagement? If yes, how could the usage of BOM1 through inclusion in a pom.xml can use the dependencies from BOM2 in a project? Thanks in advance! To better explain the situation, the below works when i include both of the in the pom.xml of the service:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot-dependencies.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>my.custom.bom</groupId>
                <artifactId>my.custom.bom</artifactId>
                <version>${my.custom.bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

Whereas the following does notwhen I include it in the pom.xml of the service:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>my.custom.bom</groupId>
                <artifactId>my.custom.bom</artifactId>
                <version>${my.custom.bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

And the my.custom.bom in the second situation includes the spring-boot-dependencies like so:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot-dependencies.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

To summarize when pom.xml includes BOM1 and BOM2 works, but when pom.xml includes BOM1 and BOM1 includes BOM2 no longer works.

Charles
  • 570
  • 11
  • 29
  • 1
    Simple answer: Yes you can. You define the BOM1 in your project and you can use the dependencies in your own project without defining the versions ? Or what exactly is the question? Maybe I misunderstand your question? – khmarbaise Jan 19 '22 at 21:38
  • The simple problem is if I include BOM1 and BOM2 in the same dependencyManagement of a pom.xml everything works, however if I include BOM1 in the dependencyManagement of BOM2 and I include BOM2 in the dependencyManagement of pom.xml then the service no longer works. I'd like to make that scenario work. The whole question is around how can I include a single BOM that contains as many BOMs as I want? Thanks! – Charles Jan 20 '22 at 07:59
  • 1
    Without a concrete example it's hard to figure out what the problem really is... ? Best would be an example on Github or alike and of course describe in detail what exactly: " then the service no longer works" really means? – khmarbaise Jan 20 '22 at 08:02
  • Basically I want to include one single BOM in the dependencyManagement of the service pom.xml. That single BOM should refer as many BOMs as it wants. After I do that the service builds nicely but at startup it complains about some missing dependencies and this puzzles me. Why with separate BOMs inclusions in the dependencyManagement it works and when I include one single BOM that includes other BOMs it no longer works? – Charles Jan 20 '22 at 08:08
  • 2
    @Charles It is perfectly fine to include BOMs in other BOMs. But note that if the BOMs overlap, you might end up with different versions of your artifacts depending on the order of the BOMs. – J Fabian Meier Jan 20 '22 at 09:08
  • 1
    @JFabianMeier your answer is correct, I just don't know how to mark it as correct. Also it is worth saying that the order of BOMs inclusion in the uber BOM matters. – Charles Jan 31 '22 at 16:52

0 Answers0