gpt4 book ai didi

gradle - 对于特定依赖项,Gradle覆盖一般的transitive = false

转载 作者:行者123 更新时间:2023-12-03 03:22:54 24 4
gpt4 key购买 nike

在用gradle玩了一些之后,我偶然发现了以下行为,并且我不确定这是否如预期或做错了什么。

默认情况下,我通过告诉编译配置transitive false排除了所有传递依赖项。但是对于特定的依赖项,我只想包含传递性依赖项,因此我在依赖项声明中添加了transitive true

但是碰巧的是,gradle忽略了我的覆盖。

这是预期的吗?难道我做错了什么?

以下是一个示例:

build.gradle

apply plugin: 'java'

repositories {
jcenter()
}

configurations {
compile {
transitive false
}
testCompile {
transitive false
}
}

dependencies {
testCompile('junit:junit:4.12') { transitive true }
}

输出

包括默认的传递依赖项
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

testCompile - Compile classpath for source set 'test'.
\--- junit:junit:4.12
\--- org.hamcrest:hamcrest-core:1.3

BUILD SUCCESSFUL

Total time: 3.404 secs

默认情况下不包括传递依赖项,但包括特定依赖项
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

testCompile - Compile classpath for source set 'test'.
\--- junit:junit:4.12

BUILD SUCCESSFUL

Total time: 3.352 secs

最佳答案

我不知道是否可以这样做,因为您已经声明了该配置以排除传递依赖项。我看到的另一种模式是相反的,在依赖声明中包括传递和排除。

configurations {
compile {
transitive false
}
testCompile {
transitive false
}
}

dependencies {
testCompile('junit:junit:4.12') { exclude module: 'exclude.this' }
}

或更改配置以排除您想要的内容以外的所有内容

关于gradle - 对于特定依赖项,Gradle覆盖一般的transitive = false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29706033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com