gpt4 book ai didi

java - Gradle 6 : get the list of implementation dependencies programmatically

转载 作者:行者123 更新时间:2023-12-02 09:13:40 25 4
gpt4 key购买 nike

我有一个 Java 项目的 build.gradle 文件,如下所示:

group "com.example"

dependencies {
implementation project(':project:project-base')
}

如何以编程方式获取实现依赖项列表?

我期望的是这样的:

configurations.compile.dark.magick.moreMagicDependencies()

返回一组依赖项进行筛选,但我可能遗漏了一些重要的东西。

谢谢!

最佳答案

我认为您可以像下面的代码一样使用resolvedConfiguration。请注意,“实现”无法直接解决(尝试..)。

但是你可以使用例如。 compileClasspath(如果适合您的情况);还有一些其他配置扩展了“实现”(参见 Java Library plugin.. 中的图表)。

调用下面的代码,例如gradle :mymodule:dumpDependency

apply plugin: 'java-library'
dependencies {
implementation 'org.springframework:spring-web:5.2.1.RELEASE'
}
task dumpDependencies {
doLast {
def resolved = configurations.compileClasspath.resolvedConfiguration
println "files=$resolved.files"
resolved.resolvedArtifacts.each {
artifact-> println "artifact=$artifact"
}
}
}
<小时/>

编辑另请注意,compile 已弃用,如果您使用 implementation ..,则 compile 依赖项将为空(您可以使用 gradle :module1:dependencies 当然)。

关于java - Gradle 6 : get the list of implementation dependencies programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59182563/

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