Gradle - 什么是“运行时”依赖配置用于? [英] Gradle - what is "runtime" dependency configuration used for?

查看:142
本文介绍了Gradle - 什么是“运行时”依赖配置用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮我理解什么是使用 runtime 依赖关系配置(由Java插件提供)的典型用例?



在Gradle用户指南中,表23.5。 Java插件 - 依赖配置,我可以看到运行时配置没有被任何任务使用 - 例如, 编译配置由 compileJava 任务使用。



那么运行时依赖项对<?>有用吗?

运行时配置适用于运行时需要但不在编译时需要的库(例如JDBC驱动程序和SLF4J api实现)。

您可以将它们添加到您的编译配置中,但是它们会在编译类路径中,并且您可能会意外引入编译依赖关系实现而不是API。



它不是由容器提供的库 - 它实际上是如何为应用程序提供库,同时确保您避难对他们引入了编译依赖性。


Can you please help me understand what are the typical use-cases in which one would use the runtime dependency configuration (provided by the Java plugin)?

In the Gradle user-guide, Table 23.5. Java plugin - dependency configurations, I can see that the runtime configuration is not used by any tasks - as opposed to e.g. the compile configuration which is used by the compileJava task.

What then is the runtime dependency useful for?

解决方案

The runtime configuration is for libraries that are needed at runtime but NOT at compile time (For example JDBC drivers and SLF4J api implementations).

You could just add them to your compile configuration, but then they would be on the compile classpath and you would run the risk of accidentally introducing a compile dependency on something from the implementation rather than the api.

It is not for libraries that are 'provided' by a container - it is actually how you provide libraries to your app while making sure you haven't introduced a compile depencency on them.

这篇关于Gradle - 什么是“运行时”依赖配置用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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