[英]Gradle distribution plugin: add files from subprojects in separate folders
I have a multiproject build (projectA) with subprojects projectB and projectC. 我有一个带有子项目projectB和projectC的多项目版本(projectA)。 Each of the subprojects have resources that I would like to add to a zip.
每个子项目都有我想添加到zip中的资源。 The resources for projectB should be in a folder called projectB in the zip.
projectB的资源应位于zip中名为projectB的文件夹中。
I am using the distribution plugin to create the zip. 我正在使用分发插件来创建zip。 This code works, but I would some code that will work regardless of the number and names of subprojects.
这段代码有效,但是无论子项目的数量和名称如何,我都会使用一些代码。
distributions {
release {
baseName 'release'
contents {
into('projectB') {
from 'projectB/src/main/resources/'
}
into('projectC') {
from 'projectC/src/main/resources/'
}
}
}
}
I tried the following: 我尝试了以下方法:
distributions {
release {
baseName 'release'
contents {
subprojects.each {
p -> into(p.name + '-resources') {
from p.projectDir + '/src/main/resources/config'
}
}
}
}
}
but that doesn't compile. 但这不能编译。
Any suggestions how to accomplish this? 任何建议如何做到这一点?
No sure why, but it works in the following way: 不知道为什么,但是它可以通过以下方式工作:
apply plugin: 'distribution'
distributions {
release {
baseName 'release'
contents {
subprojects.each { p ->
into("${p.name}-resources") {
from("${p.projectDir}/src/main/resources/config")
}
}
}
}
}
Ok, got it. 好的,我知道了。 This line was causing problems:
这条线引起了问题:
from(p.projectDir + "/src/main/resources/config")
You can't add File
to String
. 您不能将
File
添加到String
。 So both will do the job: 因此,两者都能胜任:
from(p.projectDir.toString() + "/src/main/resources/config")
from("${p.projectDir}/src/main/resources/config")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.