正如标题所说,这就是问题所在。 我有一个带有模块的android风格的应用程序。该应用程序在android-studio和TeamCity服务器中使用gradle编译。我们有自定义任务来创建看起来像这样的代码覆盖:
task codeCoverageReport(type: JacocoReport) {
// Gather execution data from all subprojects
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
//Build class & source dirs
def classExcludes =['**/R.class',
'**/R$*.class',
'**/BuildConfig.class',
'**/*$InjectAdapter*.class',
'**/*$ModuleAdapter*.class',
'**/*$ViewInjector*.class']
sourceDirectories = files();
classDirectories = files();
subprojects.each{
sourceDirectories += files(it.projectDir.absolutePath + '/src/main/java')
def path1 = it.buildDir.absolutePath + '/intermediates/classes/debug'
def path2 = it.buildDir.absolutePath + '/classes/main'
classDirectories += fileTree(dir: path1, excludes: classExcludes, includes: ['**/*.class'])
classDirectories += fileTree(dir: path2, excludes: classExcludes, includes: ['**/*.class'])
}
reports {
xml.enabled true
html.enabled true
html.destination "${buildDir}/reports/jacoco"
csv.enabled false
}
doFirst {
fileTree(dir: project.rootDir.absolutePath,includes: ['**/classes/**/*.class']).each {File file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}
现在,问题是代码覆盖率仅针对模块创建,而不是针对应用程序(主模块)创建。一段时间后,我明白这是因为调味 - 模块没有味道,所以他们只有一个Jacoco exec文件,但app(主模块)有味道,所以Jacoco创建了许多exec文件,不知道哪个一个拿。 在谷歌搜索解决方案后,我找到了一种方法来解决这个问题 - 但这创建了each module separately的报告,但这并没有多大帮助。我还试图在执行数据中包含一个特定的执行数据的exec,但是我不知道如何创建适用于所有风格的东西。我找到了这样的solution之类的东西,但由于某种原因,这与Jacoco没有用。 使用模块和风格为app创建代码覆盖的正确方法是什么? 谢谢, 奥马尔