How does Gradle's configurations hierarchy work?

…衆ロ難τιáo~ 提交于 2019-12-10 18:28:08

问题


I know there are four basic configurations, compile, runtime, testCompile, and testRuntime. If I put in a dependency like this:

runtime group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.3'

This means this dependency is available under runtime and compile, correct? But what about testCompile and testRuntime? Is it available for these configurations as well? If I add my own configuration, do I have to specify where it exists in the hierarchy? What happens if I don't? The documentation didn't really make this clear.


回答1:


The definition for those 4 configuration are as follow for the java plugin :

compile The dependencies required to compile the production source of the project.

runtime The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies.

testCompile The dependencies required to compile the test source of the project. By default, also includes the compiled production classes and the compile time dependencies.

testRuntime The dependencies required to run the tests. By default, also includes the compile, runtime and test compile dependencies.

you can also check https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations, it has pretty graph and table:

When you declare a new configuration you can define what other configuration it extends, for example Gradle In Action takes the example with Geb, you would define new configuration as

configurations {
    functTestCompile.extendsFrom testCompile
    functTestRuntime.extendsFrom testRuntime
}

If you dont, you assume those configuration do not need to benefit from another one and its standalone, you will need to define all dependencies this configuration requires.



来源:https://stackoverflow.com/questions/32354568/how-does-gradles-configurations-hierarchy-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!