14

Maven BOM

 4 years ago
source link: https://sergiuoltean.com/2018/11/29/maven-bom/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Maven

Maven BOM

BOM stands for Bill of Materials. Basically we can use it to store in one place all the dependencies with their versions. It’s useful in the case microservices are used to make sure same versions are used everywhere. Of course this is not necessarily a requirement for microservices, as you have the choice to build it how you want. No need to use the same libraries everywhere. But the developer in us screams for consistency. If you’re familiar with spring boot, you may check the way they are doing dependency management with bom.

photo-1534322869500-14fc9f5f5767?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=edbdf7bf9be18bbb172602d7f392f239&auto=format&fit=crop&w=1650&q=80

We can import it in two ways:

  • as dependency
  • as parent pom

Considering this bom (which is just a pom file)

<?xml version="1.0" encoding="UTF-8"?>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sergiuoltean.test</groupId>
<artifactId>bom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>        
<docker-maven-plugin.version>0.27.1</docker-maven-plugin.version>       
<spring-cloud.version>Greenwich.M1</spring-cloud.version>
<jaxb-api.version>2.3.0</jaxb-api.version>
<jjwt.version>0.10.5</jjwt.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>

When importing as parent pom you will get both plugins and dependencies defined only in one place. 

<?xml version="1.0" encoding="UTF-8"?>
<artifactId>commons</artifactId>  
<packaging>pom</packaging>  
<version>1.0-SNAPSHOT</version
<parent>    
<groupId>com.sergiuoltean.test</groupId>    
<artifactId>bom</artifactId>    
<version>1.0-SNAPSHOT</version>     
<relativePath/> 
</parent>
</project>

 Ideally this should be placed in a commons module/repo and all services should import it.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK