如何创建包含Android应用程序中使用的依赖项的Zip文件?
Context
包含所有应用程序依赖项的Zip文件由Nexus IQ服务器使用 . 此产品可以分析依赖关系,以确定是否存在任何安全漏洞或许可问题 .
Problem
在早期版本的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 .
Questions
-
应该使用哪些配置(或配置集)来捕获Android应用程序中使用的依赖项?
-
任务如何解决配置中的依赖关系?
1 回答