maven范围编译和JAR打包之间的区别 [英] Difference between maven scope compile and provided for JAR packaging

查看:1580
本文介绍了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.

回顾:


  • 依赖关系是不可传递的(正如你所提到的)

  • 提供的范围仅在编译和测试类路径中可用,而编译范围在所有类路径中都可用。

  • 提供的依赖项未打包

这篇关于maven范围编译和JAR打包之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆