android - Gradle:如何获取项目的所有模块依赖项
问题描述
我正在尝试编写一个 Gradle 插件,该插件在特定 Android 应用程序的所有源代码上运行 Checkstyle,包括该应用程序正在使用的所有变体和所有库模块,并生成一个没有重复错误的报告。目前我能够成功地通过所有变体运行它并生成没有重复的报告,但我不知道如何获取应用程序正在使用的模块列表。
所以,基本上,如果我有一个具有这种结构的项目:
MyProject
+-MyAppFoo
+-MyAppBar
+-FeatureA
+-FeatureB
+-FeatureC
+-Core
并且该应用程序MyAppFoo
依赖于模块FeatureA
,FeatureC
并且FeatureA
依赖于Core
我希望能够访问的项目实例FeatureA
,Core
并FeatureC
获取它们的源和类路径。
我当前的代码如下所示,我将其直接应用于项目的一个应用程序模块(例如。MyAppFoo
):
apply plugin: 'checkstyle'
afterEvaluate {
def variants
if (project.plugins.hasPlugin('com.android.application')) {
variants = android.applicationVariants
} else if (project.plugins.hasPlugin('com.android.library')) {
variants = android.libraryVariants
} else {
return
}
def dependsOn = []
def classpath
def source
variants.all { variant ->
dependsOn << variant.javaCompiler
if (!source) {
source = variant.javaCompiler.source.filter { p ->
return p.getPath().contains("${project.projectDir}/src/main/")
}
}
source += variant.javaCompiler.source.filter { p ->
return !p.getPath().contains("${project.projectDir}/src/main/")
}
if (!classpath) {
classpath = project.fileTree(variant.javaCompiler.destinationDir)
} else {
classpath += project.fileTree(variant.javaCompiler.destinationDir)
}
}
def checkstyle = project.tasks.create "checkstyle", Checkstyle
checkstyle.group = "Verification"
checkstyle.dependsOn dependsOn
checkstyle.source source
checkstyle.classpath = classpath
checkstyle.exclude('**/BuildConfig.java')
checkstyle.exclude('**/R.java')
checkstyle.exclude('**/BR.java')
checkstyle.showViolations true
project.tasks.getByName("check").dependsOn checkstyle
}
我想要的是一个project
仅包含我MyAppFoo
正在使用的模块的 s 列表,当我运行时,我gradle :MyAppFoo:checkstyle
想在模块MyAppFoo
、FeatureA
和.Core
FeatureC
解决方案
推荐阅读
- flutter - 用@freezed 装饰的类不能有可变属性
- java - 如何配置 AWS 用户 cognito 身份验证流程以在 Java sdk 后端生成身份令牌、访问令牌?
- javascript - 选择具有匹配数据属性的最近元素
- shell - 将具有多个名称-多值对的文件转换为 Rows shell 脚本
- xml - 使用 XSLT 显示所有元素的元素 repititions 之间的 Subtotolas
- php - Laravel 7浏览器不下载文件
- arrays - 将特定值移动到随机填充数组的末尾
- asp.net-core - 为托管的 blazor 实现进度条
- c++ - 字符串文字中换行符的换行计数器 [更新]
- reactjs - React/redux combineReducers 问题