maven課程 專案管理利器-maven 3-7 maven依賴範圍 2星
阿新 • • 發佈:2018-11-02
本節主要講了maven的依賴範圍:
在pom.xml dependency標籤的scope中。eclipse中有編譯的路徑,maven中有編譯,執行,測試的路徑。
1 scope為test,為測試路徑,多為junit jar包
2 scope為compile,為預設級別,編譯測試執行都有效
3 scope為provided,編譯和測試的時候有效
4 scope為runtime,執行和測試的時候有效 (如:jdbc驅動的實現)
5 scope為system,和compile一致,但是可移植能力差,引用的java_home(環境變數),更換電腦後將不能正常工作
6 scope為import,它只使用在dependencyManager中,表示從其他的pom中匯入dependency的配置。
自己理解的:
maven編譯需要jar包,執行需要jar包,測試也需要jar包。
scope為test:
<dependency> <groupId>junit</groupId> <!-- 此處是包名--> <artifactId>junit</artifactId> <!-- 此處是專案名--> <version>4.1.0</version> <!-- 此處是maven版本號--> <scope>test</scope> </dependency>
scope為import:
<dependency> <groupId>maven</groupId><artifactId>A</artifactId> <version>1.0</version> <type>pom</type> <scope>import</scope> </dependency>
maven官網關於依賴機制的介紹:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html