首页 > 解决方案 > How to access collection of source directories of all included build in composite build of Gradle?

问题描述

I have a gradle project with composite build. I have to get the source files collection to use in jacoco instrumentation. Is there any to get the source directories of all included builds.

settings.gradle

rootProject.name = 'my-composite'

includeBuild 'my-app'
includeBuild 'my-utils'

I am currently using files method to get the collection in build.gradle

project.ext.files1 = 
fileTree("C:/my-composite/my-app/src").matching {
    include '*.java'
}

project.ext.files2 = 
fileTree("C:/my-composite/my-utils/src").matching {
    include '*.java'
}

project.ext.allFiles = project.ext.files1.plus(project.ext.files2) 

can we generate the source list dynamically using gradle.includedBuild('my-app')? (or) Is there any way to use a task to return source directory of each inculdede build? or is there any other way to do it?

标签: javagradlegroovybuild-tools

解决方案


应该能够做到:

fileTree(gradle.includedBuild("my-app").projectDir.resolve("src")).matching {
    include("*.java")
}

推荐阅读