maven scope

  • compile,缺省值,適用于所有階段,會隨著項目一起發布。
    compile is the default scope; all dependencies are compile-scoped if a scope is not supplied.compile dependencies are available in all classpaths, and they are packaged.

  • provided,類似compile,期望JDK、容器或使用者會提供這個依賴。如servlet.jar。
    provided dependencies are used when you expect the JDK or a container to provide them. For example, if you were developing a web application, you would need the Servlet API available on
    the compile classpath to compile a servlet, but you wouldn’t want to include the Servlet API in the packaged WAR; the Servlet API JAR is supplied by your application server or servlet container.
    provided dependencies are available on the compilation classpath (not runtime). They are not transitive, nor are they packaged.

  • runtime,只在運行時使用,如JDBC驅動,適用運行和[測試]階段。
    runtime dependencies are required to execute and test the system, but they are not required for compilation. For example, you may need a JDBC API JAR at compile time and the JDBC driver implementation only at runtime.

  • test,只在測試時使用,用于編譯和運行測試代碼。不會隨項目發布。
    test-scoped dependencies are not required during the normal operation of an application, and they are available only during test compilation and execution phases.

  • system,類似provided,需要顯式提供包含依賴的jar,Maven不會在Repository中查找它。
    The system scope is similar to provided except that you have to provide an explicit path to the JAR on the local file system. This is intended to allow compilation against native objects that may
    be part of the system libraries. The artifact is assumed to always be available and is not looked up in a repository. If you declare the scope to be system, you must also provide the systemPath
    element. Note that this scope is not recommended (you should always try to reference dependencies
    in a public or custom Maven repository).


The second dependency is a test-scoped dependency on JUnit. You would use a testscoped dependency when you need to reference this library only during testing.
The last dependency in Project Dependencies is a dependency on the Servlet 2.4 API. The last dependency is scoped as a provided dependency. You would use a provided scope when the application you are developing needs a library for compilation and testing, but this library is supplied by a container at runtime.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,890評論 0 23
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,541評論 5 6
  • 每天的生活很簡單 兩點一線。公司-宿舍 吃飯睡覺上班 24小時-10小時宿舍=14小時公司 很辛苦很累很孤獨。 ...
    小珺主閱讀 239評論 1 1
  • 我們總有大堆的理由說忙,說沒時間,哪怕是面對自己所愛的人、所喜歡的事。 我不單單在說你,也在說我自己。...
    若臨閱讀 277評論 0 0
  • 本覺時過境遷 卻道回憶延綿 惘若舊時浮現 心中揮之不去 深深淺淺終有變 奈何情深纏紛亂 散去晴日有時見
    慢慢走wzz閱讀 201評論 0 0