Maven:什么是“运行时"?范围目的? [英] Maven : what is the "runtime" scope purpose?

查看:74
本文介绍了Maven:什么是“运行时"?范围目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
了解编译与运行时的依赖关系

Possible Duplicate:
Understanding Compile- vs Run-time Dependencies

我知道具有运行时"范围的依赖项将在运行时可用,而不在编译时可用.但是我不明白你为什么要那样做!为什么不简单地使用编译"范围呢?

I understand that a dependency with the "runtime" scope will be available at runtime and not at compile time. But I don't understand why you could want that! Why not simply use the "compile" scope instead?

文档并不是真的帮助.有什么主意吗?

The docs don't really help. Any idea?

推荐答案

运行时对于单元测试和运行时(而不是编译时)所需的依赖项很有用.通常,这可能是动态加载的代码,例如JDBC驱动程序,这些代码并未在程序代码中直接引用.

runtime is useful for dependencies required for unit tests and at runtime, but not at compile time. This may typically be dynamically loaded code, such as JDBC drivers, which are not directly referenced in the program code.

将依赖项设置为运行时可确保对代码没有意外的依赖关系,并且还避免了该依赖关系的传递.这样,例如,如果模块A对库X具有运行时依赖关系,而模块B对模块A依赖,则它 not 不会继承对库X的依赖关系.使用提供"或编译" 导致B依赖X.

Setting dependency to runtime ensure that there isn't an accidental dependency on the code, and also keeps the dependency from being transitive. So that, for example, if module A has a runtime dependency on library X, and module B depends on module A, it does not inherit the dependency on library X. Using "provided" or "compile" would cause B to depend on X.

这篇关于Maven:什么是“运行时"?范围目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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