Java Gradle 中的传递 = true 究竟做了什么(wrt crashlytics)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31731014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does transitive = true in Gradle exactly do (w.r.t. crashlytics)?
提问by Steve Kuo
What does Gradle transitive = true
do exactly? It is not clear from the Gradle documentation. This is in the context of compile
within build.gradle
. In my case I'm depending Android's crashlytics.
Gradletransitive = true
究竟做了什么?Gradle 文档中并不清楚。这是在上下文compile
中build.gradle
。就我而言,我依赖于 Android 的 crashlytics。
compile('com.crashlytics.sdk.android:crashlytics:2.2.2@aar') {
transitive = true;
}
Several Gradle docs (hereand here) imply that "transitive" defaults to true. Yet removing transitive = true
results in transitive dependencies not being brought in (in particular KitGroup
).
几个 Gradle 文档(此处和此处)暗示“传递”默认为 true。然而,删除transitive = true
导致未引入传递依赖项的结果(特别是KitGroup
)。
class file for io.fabric.sdk.android.KitGroup not found
The docs say it defaults to true, yet the actual behavior seems to be the opposite.
文档说它默认为 true,但实际行为似乎相反。
I am running Gradle 2.2.1. Perhaps the behavior changed between 2.2 and 2.4?
我正在运行 Gradle 2.2.1。也许行为在 2.2 和 2.4 之间发生了变化?
Edit: Related Transitive dependencies not resolved for aar library using gradle
回答by Steve Kuo
transitive
controls transitivity. Gradle normally defaults to transitive, except when it doesn't. There's a bug with transitivity and classifiers, see https://issues.gradle.org/browse/GRADLE-3188.
transitive
控制传递性。Gradle 通常默认为可传递的,除非它不传递。传递性和分类器存在错误,请参阅https://issues.gradle.org/browse/GRADLE-3188。
回答by Sam Dozor
My guess is that the Crashlytics artifact to which you're referring manually specifies dependencies as nottransitive (transitive=false
) so that you aren't forced to bring those dependencies in by default. That's why you're seeing the opposite behavior. For example some developers may not want to pull in all of Google Play Services or whatever else Crashlytics may use if present.
我的猜测是,您手动引用的 Crashlytics 工件将依赖项指定为不可传递的 ( transitive=false
),这样您就不会被迫默认引入这些依赖项。这就是为什么你会看到相反的行为。例如,某些开发人员可能不想引入所有 Google Play 服务或 Crashlytics 可能使用的任何其他服务(如果存在)。
So, by removing that, Gradle no longer pulls in the dependency, and it fails to build. You can specify that dependency manually if you need to.
因此,通过删除它,Gradle 不再引入依赖项,并且构建失败。如果需要,您可以手动指定该依赖项。
That being said- I think the bigger issue at hand is that you shouldn't be referencing the Crashlytics artifact directly - you should be using Fabric, and pulling in Crashlytics as a result: https://dev.twitter.com/fabric/android/integrating
话虽如此- 我认为手头更大的问题是您不应该直接引用 Crashlytics 工件 - 您应该使用 Fabric,并因此引入 Crashlytics:https://dev.twitter.com/fabric/安卓/集成
回答by Gabriele Mariotti
You are using the @aar
notation.
It means that you want to download only the aar artifact, and no dependencies.
You can check this part of documentation:
Check the 1.4.1.2. Artifact only notation
section:
您正在使用@aar
符号。
这意味着您只想下载 aar 工件,而没有任何依赖项。
您可以检查这部分文档:
检查1.4.1.2. Artifact only notation
部分:
An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.
仅工件表示法创建模块依赖项,该依赖项仅下载具有指定扩展名的工件文件。现有的模块描述符被忽略。
Using the @aar
notation if you want to download the dependencies, you should add transitive=true
.
@aar
如果要下载依赖项,请使用表示法,您应该添加transitive=true
.
I'd expect that omitting @aar it should work without adding the transitive attribute.
我希望省略 @aar 它应该可以在不添加传递属性的情况下工作。
回答by user6703435
Sets whether this dependency should be resolved including or excluding its transitive dependencies. The artifacts belonging to this dependency might themselve have dependencies on other artifacts. The latter are called transitive dependencies.
设置是否应解决此依赖项,包括或排除其传递依赖项。属于此依赖项的工件本身可能依赖于其他工件。后者称为传递依赖。
回答by Hongyuan
Gradle follows transitive dependencies by default. If you want to turn that off for a particular library, use the transitive flag.
Gradle 默认遵循传递依赖。如果要为特定库关闭它,请使用传递标志。
Changing the value of the transitive flag to false prevents the download of transitive dependencies, so you'll have to add whatever is required yourself. If you only want a module jar, without any additional dependencies, you can specify that as well.
将传递标志的值更改为 false 可防止下载传递依赖项,因此您必须自己添加所需的任何内容。如果您只需要一个模块 jar,而没有任何其他依赖项,您也可以指定它。
回答by Vaiden
On a more general note:
Setting transitive = false
on the crashlytics
library causes gradle to ignore all libraries required by crashlytics
(="transient libraries") and not download and link them.
更一般的说明:transitive = false
在crashlytics
库上设置会导致 gradle 忽略crashlytics
(="transient libraries")所需的所有库,而不是下载和链接它们。
You would have to either manually add the required libraries to your project or rely on other transient libraries added by other dependencies.
您必须手动将所需的库添加到您的项目中,或者依赖其他依赖项添加的其他瞬态库。
Default for gradle is transitive = true
.
gradle 的默认值是transitive = true
.
Examples and full explanation here: http://www.devsbedevin.net/android-understanding-gradle-dependencies-and-resolving-conflicts/
这里的例子和完整解释:http: //www.devsbedevin.net/android-understanding-gradle-dependencies-and-resolving-conflicts/