如何创建包含 Android 应用程序中使用的依赖项的 Zip 文件?
上下文
Nexus IQ 服务器使用包含所有应用程序依赖项的 Zip 文件。该产品可以分析依赖关系以确定是否存在任何安全漏洞或许可问题。
问题
在早期版本的 Gradle(例如 3.3 及以下)中,以下 Gradle 任务用于创建依赖项的 Zip 文件。
task dependenciesZip(type: Zip) {
from configurations.compile
}
升级到 Gradle 4.1 后,上述任务停止工作。
上述任务的一个问题是所使用的配置。迁移到 Gradle 4.1 时,所有应用程序依赖项都从编译 更改为实现。因此,编译配置不包含任何要包含在 Zip 文件中的依赖项。
为了解决此问题,上述任务已更新为以下内容:
task dependenciesZip(type: Zip) {
from configurations.implementation
}
但是,上述任务运行失败并出现以下错误:
./gradlew :app:dependenciesZip
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:dependenciesZip'.
> Resolving configuration 'implementation' directly is not allowed
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
此失败是由 Gradle 尝试解析实现配置时抛出的 IllegalStateException 引起的。 isCanBeResolved() 方法为实现配置返回 false。
问题
- 应该使用什么配置(或一组配置)来捕获 Android 应用程序中使用的依赖项?
- 任务如何解决配置中的依赖关系?
最佳答案
task copyDependencies(type: Copy) {
configurations.getAt("implementation").setCanBeResolved(true)
println("implementation canBeResolved change to :"+configurations.getAt("implementation").canBeResolved)
from configurations.getAt("implementation")
into ".\\dependencies"
}
关于android - 如何创建 Android 应用程序中使用的依赖项的 Zip 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48195162/