Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Gradle:如何获取项目的所有模块依赖项_Android_Gradle_Checkstyle_Gradle Plugin - Fatal编程技术网

Android Gradle:如何获取项目的所有模块依赖项

Android Gradle:如何获取项目的所有模块依赖项,android,gradle,checkstyle,gradle-plugin,Android,Gradle,Checkstyle,Gradle Plugin,我正在尝试编写一个Gradle插件,在特定Android应用程序的所有源代码上运行Checkstyle,包括应用程序正在使用的所有变体和所有库模块,并生成一个没有重复错误的报告。目前,我能够成功地运行所有变体并生成一份没有重复的报告,但我不知道如何获取应用程序正在使用的模块列表 因此,基本上,如果我有一个具有这种结构的项目: MyProject +-MyAppFoo +-MyAppBar +-FeatureA +-FeatureB +-FeatureC +-Core 应用程序MyAppFoo依

我正在尝试编写一个Gradle插件,在特定Android应用程序的所有源代码上运行Checkstyle,包括应用程序正在使用的所有变体和所有库模块,并生成一个没有重复错误的报告。目前,我能够成功地运行所有变体并生成一份没有重复的报告,但我不知道如何获取应用程序正在使用的模块列表

因此,基本上,如果我有一个具有这种结构的项目:

MyProject
+-MyAppFoo
+-MyAppBar
+-FeatureA
+-FeatureB
+-FeatureC
+-Core
应用程序
MyAppFoo
依赖于模块
FeatureA
FeatureC
FeatureA
依赖于
Core
我希望能够访问
FeatureA
Core
FeatureC
的项目实例,以获取它们的源代码和类路径

我当前的代码是这样的,我将它直接应用于项目的一个应用程序模块(例如,
MyAppFoo
):

应用插件:“checkstyle”
后评价{
def变体
if(project.plugins.hasPlugin('com.android.application')){
variants=android.applicationVariants
}else if(project.plugins.hasPlugin('com.android.library')){
variants=android.libraryVariants
}否则{
返回
}
def dependsOn=[]
def类路径
def源
variants.all{variant->
德彭森
返回p.getPath().contains(“${project.projectDir}/src/main/”)
}
}
source+=variant.javaCompiler.source.filter{p->
return!p.getPath()包含(“${project.projectDir}/src/main/”)
}
if(!classpath){
classpath=project.fileTree(variant.javaCompiler.destinationDir)
}否则{
classpath+=project.fileTree(variant.javaCompiler.destinationDir)
}
}
def checkstyle=project.tasks.create“checkstyle”,checkstyle
checkstyle.group=“验证”
checkstyle.dependsOn dependsOn
checkstyle.source源
checkstyle.classpath=类路径
checkstyle.exclude('**/BuildConfig.java')
checkstyle.exclude(“**/R.java”)
checkstyle.exclude(“**/BR.java”)
checkstyle.showVillations为true
project.tasks.getByName(“check”).dependsOn checkstyle
}
我想要的是一个
project
列表,其中只包含我的
MyAppFoo
正在使用的模块,这是我运行
gradle:MyAppFoo:checkstyle
时需要的,我想在模块
MyAppFoo
FeatureA
Core
FeatureC
上运行它

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
}