Gradle subproject name different than folder name

GradleDirectorySubprojectGradle Multi-Project-Build

Gradle Problem Overview


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 (settings.gradle) it has to have the folder name otherwise it won't find it (same for the compile project(':ProjectName')).

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.

Thank you.

Gradle Solutions


Solution 1 - 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"

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

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.

Solution 2 - Gradle

This is Kotlin DSL equivalent of Peter Niederwieser's answer.

settings.gradle.kts:

rootProject.name = "MyApp"

include(":Narengi")
project(":Narengi").name = "Bunny"

// OR

include(":Bunny")
project(":Bunny").projectDir = file("Narengi/")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGreg HillView Question on Stackoverflow
Solution 1 - GradlePeter NiederwieserView Answer on Stackoverflow
Solution 2 - GradleMahozadView Answer on Stackoverflow