<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Maven BOM – 物料清單依賴項 > 原文: [https://howtodoinjava.com/maven/maven-bom-bill-of-materials-dependency/](https://howtodoinjava.com/maven/maven-bom-bill-of-materials-dependency/) 如果您在項目中為依賴項管理使用過 [**maven**](//howtodoinjava.com/maven/ "Maven Tutorials"),那么您必須至少遇到一個問題,或者可能更多。 問題是**版本不匹配**。 通常,當您獲得一些依賴項并將其相關的依賴項與特定版本協作時,就會發生這種情況。 并且,如果您已經包含了具有不同版本號的那些依賴項,則它們可能在編譯時以及運行時都面臨不良結果。 理想情況下,為避免上述問題,您需要明確排除相關的依賴項,但您很有可能會忘記這樣做。 要解決版本不匹配的問題,您可以使用“**物料清單**”(BOM)依賴項的概念。 BOM 依賴項跟蹤版本號,并確保所有依賴項(直接和傳遞)都處于同一版本。 ## 1\. 如何添加 Maven BOM 依賴 Maven 為此提供了一個標簽`dependencyManagement`。 您需要按如下所示在此標記中添加 **maven bom** 信息。 我以 Spring Bom 文件為例。 ```java <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.0.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` 使用 BOM 的另一個好處是,根據 Spring 框架工件,您不再需要指定`version`屬性。 因此它將完全正常。 ```java <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependencies> ``` ## 每個項目都有自己的 Maven Bom 文件 請注意,沒有通用或通用的 Bom 文件。 每個項目(如果支持此功能)都提供自己的 Bom 文件并管理其相關依賴項的版本。 以下是各種 Bom 文件的幾個示例: **1)RESTEasy Maven BOM 依賴項** ```java <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-bom</artifactId> <version>3.0.6.Final</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` **2\. JBOSS Maven BOM 依賴項** ```java <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.bom</groupId> <artifactId>jboss-javaee-6.0-with-tools</artifactId> <version>${some.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` **3)Spring Maven BOM 依賴項** ```java <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.0.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` **4)Jersey Maven BOM 依賴項** ```java <dependencyManagement> <dependencies> <dependency> <groupId>org.glassfish.jersey</groupId> <artifactId>jersey-bom</artifactId> <version>${jersey.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` 這些只是幾個例子。 因此,下次您在 Maven 中工作時,請嘗試探索此功能。 ## 3\. Maven BOM 與 POM 首先,BOM 是普通的`pom.xml`文件 - 它們不包含源代碼,它們的唯一目的是聲明其捆綁的模塊。 它定義了將在庫中創建的所有工件的版本。 其他希望使用該庫的項目應將此 pom 導入到其 pom 的`dependencyManagement`部分。 POM 文件不僅僅是依賴項。 例如組織和許可證,項目所在的 URL,項目的依賴項,插件,配置文件等等。 它還控制項目的完整構建過程。 學習愉快! 參考: [POM – Maven 文檔](https://maven.apache.org/pom.html) [Maven 依賴機制](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看