简体   繁体   English

Gradle - 什么是“运行时”依赖配置用于?

[英]Gradle - what is “runtime” dependency configuration used for?

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)? 你能帮我理解一下使用runtime依赖配置(由Java插件提供)的典型用例吗?

In the Gradle user-guide, Table 23.5. 在Gradle用户指南中, 表23.5。 Java plugin - dependency configurations , I can see that the runtime configuration is not used by any tasks - as opposed to eg the compile configuration which is used by the compileJava task. Java插件 - 依赖配置 ,我可以看到任何任务都没有使用运行时配置 - 而不是例如compileJava任务使用的compile配置。

What then is the runtime dependency useful for? 那么runtime依赖有用的是什么?

The runtime configuration is for libraries that are needed at runtime but NOT at compile time (For example JDBC drivers and SLF4J api implementations). 运行时配置适用于运行时需要的库,但不适用于编译时(例如JDBC驱动程序和SLF4J api实现)。

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. 您可以将它们添加到您的编译配置中,但是它们将在编译类路径上,并且您将冒着意外地从实现而不是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. 它不适用于由容器“提供”的库 - 它实际上是您为应用程序提供库的方式,同时确保您没有对它们引入编译依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM