Açıklaması şöyle
BOM stands for "Bill Of Materials". A BOM is a special kind of POM that is used to control the versions of a project’s dependencies and provide a central place to define and update those versions.
Açıklaması şöyle
The Bill Of Material is a special POM file that groups dependency versions that are known to be valid and tested to work together. This will reduce the developers’ pain of having to test the compatibility of different versions and reduce the chances to have version mismatches.
1. BOM Yazmak
Açıklaması şöyle
BOM elements:1. a pom packaging type: <packaging>pom</packaging>.2. a dependencyManagement the section that lists the dependencies of a project.Inside the dependencyManagement we will set all of the dependencies needed and specific versions of the dependency because it is mandatory.
Örnek
Şöyle yaparız
<project ...> <modelVersion>4.0.0</modelVersion> <groupId>reflectoring</groupId> <artifactId>reflectoring-bom</artifactId> <version>1.0</version> <packaging>pom</packaging> <name>Reflectoring Bill Of Material</name> <dependencyManagement> <dependencies> <dependency> <groupId>io.reflectoring</groupId> <artifactId>logging</artifactId> <version>2.1</version> </dependency> <dependency> <groupId>io.reflectoring</groupId> <artifactId>test</artifactId> <version>1.1</version> </dependency> </dependencies> </dependencyManagement> </project>
2. BOM'u Kullanmak
İki yöntem var.
1.BOM As A Parent Yöntemi
2.BOM as a Dependency Yöntemi2.1 BOM As A Parent Yöntemi
Bir projede tek bir parent BOM olabilir. <parent>...</parent> tagleri içine yazılır
Örnek
Şöyle yaparız
<project ...> <modelVersion>4.0.0</modelVersion> <groupId>baeldung</groupId> <artifactId>Test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Test</name> <parent> <groupId>baeldung</groupId> <artifactId>Baeldung-BOM</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> </project>
Örnek
Şöyle yaparız
<project ...> <modelVersion>4.0.0</modelVersion> <parent> <groupId>reflectoring</groupId> <artifactId>reflectoring-bom</artifactId> <version>1.0</version> </parent> <groupId>reflectoring</groupId> <artifactId>new-project</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>New Project</name> <dependency> <groupId>io.reflectoring</groupId> <artifactId>logging</artifactId> </dependency> </project>
2.2 BOM as a Dependency
Bir projede tek bir parent BOM olabilir, ancak bazen bir başka projeden de parent BOM gelebiliyor. Bu durumda BOM kendi pom.xml dosyamıza <dependencyManagement>..</dependencyManagement> olarak kopyalanabilir. Kullanırken şöyle yaparız
<type>pom</type> <scope>import</scope>
Örnek
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.5.4</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Örnek
Şöyle yaparız
<project ...> <modelVersion>4.0.0</modelVersion> <groupId>baeldung</groupId> <artifactId>Test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Test</name> <dependencyManagement> <dependencies> <dependency> <groupId>baeldung</groupId> <artifactId>Baeldung-BOM</artifactId> <version>0.0.1-SNAPSHOT</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
Örnek
Şöyle yaparız
<project ...> <modelVersion>4.0.0</modelVersion> <groupId>reflectoring</groupId> <artifactId>new-project</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>New Project</name> <dependency> <groupId>io.reflectoring</groupId> <artifactId>logging</artifactId> </dependency> <dependencyManagement> <dependencies> <dependency> <groupId>reflectoring</groupId> <artifactId>reflectoring-bom</artifactId> <version>1.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
Hiç yorum yok:
Yorum Gönder