[英]Gradle multi-project naming: How can I set a property (e.g. baseName) for all subprojects?
I started using Gradle for multi-projects.我开始使用 Gradle 进行多项目。 However, the Gradle manual does not give many hints for the best practice regarding the naming of subprojects.
但是,Gradle 手册并没有给出很多有关子项目命名最佳实践的提示。
I have the multiproject with the name 'datalogger' that consists of two subprojects 'core' and 'entries':我有一个名为“数据记录器”的多项目,它由两个子项目“核心”和“条目”组成:
- datalogger
--- core
--- entries
When I build the project, I get the jars 'core-1.0.jar' and 'entries-1.0.jar'.当我构建项目时,我得到 jars 'core-1.0.jar' 和 'entries-1.0.jar'。 How do I manage that the naming is 'datalogger-core-1.0.jar' and 'datalogger-entries-1.0.jar' in a generic way?
如何以通用方式管理命名为“datalogger-core-1.0.jar”和“datalogger-entries-1.0.jar”? I know, I could change the name of the folders as follows:
我知道,我可以按如下方式更改文件夹的名称:
- datalogger
--- datalogger-core
--- datalogger-entries
But that would not be regarded as good approach, I assume.但我认为这不会被视为好方法。 I could also manually change the
archivesBaseName
of each project.我还可以手动更改每个项目的
archivesBaseName
。 But I would rather find a way to do this in a generic way, as mentioned before.但我宁愿找到一种以通用方式执行此操作的方法,如前所述。
subprojects {
tasks.withType(Jar) {
baseName = "datalogger-$project.name"
}
}
Alternatively, you could set archivesBaseName
in a similar way. 或者,您可以以类似的方式设置
archivesBaseName
。
We're handling this by renaming the subprojects, new names will be taken into account when creating/naming your jars: ref: how to rename the project in gradle instead of using folder name? 我们通过重命名子项目来处理这个问题,在创建/命名你的jar时会考虑新名称:ref: 如何在gradle中重命名项目而不是使用文件夹名称?
include 'xxx', 'yyy'
rootProject.children.each { it.name = rootProject.name + it.name }
For Kotlin: in the root project's build file:对于 Kotlin:在根项目的构建文件中:
subprojects {
tasks.withType<Jar> {
archiveBaseName.set("${rootProject.name}-${project.name}")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.