itVincent Blog - Java Working Fun!

          技術(shù)引領(lǐng)時(shí)代!
          posts - 117, comments - 181, trackbacks - 0, articles - 12

          Maven Dependency Scope

          Posted on 2009-12-21 13:58 itVincent 閱讀(1264) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): maven

           

          Dependency scope 是用來(lái)限制Dependency的作用范圍的, 影響maven項(xiàng)目在各個(gè)生命周期時(shí)導(dǎo)入的package的狀態(tài)。

          自從2.0.9后,新增了1種,現(xiàn)在有了6種scope:

          • compile
            默認(rèn)的scope,表示 dependency 都可以在生命周期中使用。而且,這些dependencies 會(huì)傳遞到依賴的項(xiàng)目中。
          • provided
            跟compile相似,但是表明了dependency 由JDK或者容器提供,例如Servlet AP和一些Java EE APIs。這個(gè)scope 只能作用在編譯和測(cè)試時(shí),同時(shí)沒(méi)有傳遞性。        
          • runtime
            表示dependency不作用在編譯時(shí),但會(huì)作用在運(yùn)行和測(cè)試時(shí) 
          • test
            表示dependency作用在測(cè)試時(shí),不作用在運(yùn)行時(shí)。
          • system
            跟provided 相似,但是在系統(tǒng)中要以外部JAR包的形式提供,maven不會(huì)在repository查找它。 例如:

          <project>
          ...
          <dependencies>
            <dependency>
             <groupId>javax.sql</groupId>
             <artifactId>jdbc-stdext</artifactId>
             <version>2.0</version>
             <scope>system</scope>
             <systemPath>${java.home}/lib/rt.jar</systemPath>
            </dependency>
          </dependencies>
          ...
          </project>

           

          • import (Maven 2.0.9 之后新增)
            它只使用在<dependencyManagement>中,表示從其它的pom中導(dǎo)入dependency的配置,例如:    This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

            <project>

           <modelVersion>4.0.0</modelVersion>

           <groupId>maven</groupId>

           <artifactId>B</artifactId>

           <packaging>pom</packaging>

           <name>B</name>

           <version>1.0</version>

           <dependencyManagement>

              <dependencies>

                <dependency>

                  <groupId>maven</groupId>

                  <artifactId>A</artifactId>

                  <version>1.0</version>

                  <type>pom</type>

                  <scope>import</scope>

                </dependency>

                <dependency>

                  <groupId>test</groupId>

                  <artifactId>d</artifactId>

                  <version>1.0</version>

                </dependency>

              </dependencies>

           </dependencyManagement>

          </project>

          B項(xiàng)目導(dǎo)入A項(xiàng)目中的包配置

          主站蜘蛛池模板: 历史| 崇明县| 景谷| 蒙自县| 邓州市| 郓城县| 昌宁县| 南乐县| 湖口县| 曲靖市| 长岛县| 沛县| 茶陵县| 阳信县| 和静县| 萝北县| 达孜县| 鲁甸县| 凤冈县| 滦平县| 朔州市| 南宁市| 紫阳县| 石景山区| 大邑县| 申扎县| 扬中市| 读书| 丰宁| 临夏市| 雅安市| 太康县| 双辽市| 会宁县| 靖远县| 新竹市| 罗定市| 武定县| 长宁区| 常宁市| 北海市|