maven范围编译和JAR打包之间的区别
当工件构建为JAR时,maven范围编译
和提供
之间有什么区别?如果它是WAR,我明白 - 工件将包含在WEB-INF / lib中或不包含在WEB-INF / lib中。但是在JAR的情况下它并不重要 - 不包括依赖性。当它们的范围是 compile
或提供
时,它们必须在类路径上。我知道提供的
依赖项是不可传递的 - 但它只有一个区别吗?
What is the difference between the maven scope compile
and provided
when artifact is built as a JAR? If it was WAR, I'd understand - the artifact would be included or not in WEB-INF/lib. But in case of a JAR it doesn't matter - dependencies aren't included. They have to be on classpath when their scope is compile
or provided
. I know that provided
dependencies aren't transitive - but is it only one difference?
来自 Maven Doc :
编译
这是默认范围,如果未指定,则使用。编译
依赖项在项目的所有类路径中都可用。
此外,这些依赖项会传播到依赖项目。
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
提供
这很像compile,但表示您希望JDK或
容器在运行时提供依赖项。例如,当
为Java Enterprise Edition构建Web应用程序时,您需要将
设置对Servlet API和相关Java EE API的依赖性设置为
作用域,因为Web容器提供了这些类。这个
范围仅在编译和测试类路径上可用,并且
不可传递。
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
回顾:
- 依赖关系是不可传递的(正如你所提到的)
- 提供的范围仅在编译和测试类路径中可用,而编译范围在所有类路径中都可用。
- 提供的依赖项未打包