Gradle子项目名称与文件夹名称不同 [英] Gradle subproject name different than folder name

查看:917
本文介绍了Gradle子项目名称与文件夹名称不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个子项目是多项目构建(平面层次结构)的一部分。我想将它们的名称设置为与其文件夹名称不同。但是在include(setting.gradle)中它必须有文件夹名称,否则它不会找到它(对于编译项目(':ProjectName'))也是如此。)

I have a couple of subprojects that are part of a multi-project build (flat hierarchy). I want to set the name on them to be different than their folder name. However in include (setting.gradle) it has to have the folder name otherwise it won't find it (same for the compile project (':ProjectName')).

如果我尝试设置project.name,它告诉我这是只读的。原因是我们正在从Ant进行转换,并希望为Eclipse IDE保留相同的名称。至于这些工件,我们使用jar.artifactName来设置我们想要的任何名称。

If I attempt to set project.name it tells me that is read-only. The reason is that we are converting from Ant and would like to keep the same name for Eclipse IDE. As far the artifacts go, we use jar.artifactName to set whatever name we want.

谢谢,

推荐答案

项目名称只能在 settings.gradle 中更改。例如:

Project names can only be changed in settings.gradle. For example:

include "foo" // or `includeFlat`, doesn't matter

// always good to nail down the root project name, because
// the root directory name may be different in some envs (e.g. CI)
// hence the following even makes sense for single-project builds
rootProject.name = "bar" 

// change subproject name
project(":foo").name = "foofoo"

或者,您可以在 include 语句中使用所需的项目名称,稍后重新配置项目目录:

Alternatively, you can use the desired project name in the include statement, and later reconfigure the project directory:

include "foofoo"

project(":foofoo").projectDir = file("foo")

为了给出一些背景,包括 includeFlat 是他们对项目的 projectDir 使用不同的默认值。

To give some background, the only difference between include and includeFlat is that they use different defaults for the project's projectDir. Otherwise they are the same.

有关更多信息,请查看手动构建语言参考

For further information, check out Settings in the Gradle Build Language Reference.

这篇关于Gradle子项目名称与文件夹名称不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆