如何访问Gradle复合构建中所有已包含构建的源目录集合?

huangapple go评论64阅读模式
英文:

How to access collection of source directories of all included build in composite build of Gradle?

问题

settings.gradle

rootProject.name = 'my-composite';

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

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);

可以使用 gradle.includedBuild('my-app') 动态生成源代码列表吗?
还是有没有办法使用任务来返回每个已包含构建的源目录?
还有其他的方法可以实现吗?

英文:

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?

答案1

得分: 1

应该能够执行:

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

英文:

Should be able to do:

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

huangapple
  • 本文由 发表于 2020年9月29日 01:24:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/64106820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定