in springboot multimodule project, adding BOM as dependency

318 Views Asked by At

I have multiple dependencies. so I created a separate maven project with dependencies.

 <groupId>Dependency</groupId>
   <artifactId>DA</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>pom</packaging>
   
   
  <dependencies>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>1.2.3</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>1.2.3</version>
    </dependency>
  </dependencies>

Creating another spring boot project and using the above as dependency.

Parent pom :

<groupId>A</groupId>
   <artifactId>ADef</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>pom</packaging>
   
   <modules>
    <module>A1</module>
    <module>A2</module>
    </modules>
   
   <dependencyManagement>
    <dependencies>
        <dependency>
          <groupId>Dependency</groupId>
          <artifactId>DA</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <type>pom</type>
          <scope>import</scope>
        <dependency>
    </dependencies>
   
   </dependencyManagement>
   
    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>    
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>     
        </dependency>
  </dependencies>

Child pom:

 <groupId>A1</groupId>
   <artifactId>ADef</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>pom</packaging>
   
   <parent>
        <groupId>A</groupId>
        <artifactId>ADef</artifactId>
        <version>0.0.1-SNAPSHOT</version>
   </parent>
   
    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>    
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>     
        </dependency>
  </dependencies>

when i build, getting an exception says that "dependencies.dependency.version for com.google.code.gson is missing" and dependencies.dependency.version for JUnit is missing"

Can you help to fix this issue?

1

There are 1 best solutions below

0
Palak Kharbanda On

Try writing <version>1.2.3</version> for gson in parent and child pom