Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle subproject name different than folder name

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.

like image 870
Greg Hill Avatar asked Nov 21 '13 17:11

Greg Hill


People also ask

What is subproject in gradle?

In a multi-project gradle build, you have a rootProject and the subprojects. The combination of both is allprojects. The rootProject is where the build is starting from. A common pattern is a rootProject has no code and the subprojects are java projects.

How do I change the name of a project in gradle?

By default, Gradle uses the directory name as project name. You can change this by creating a settings. gradle file in the directory which specifies the project name. You can also add a description to your project via the build.

What is a multi module project gradle?

A multi-project build in Gradle consists of one root project, and one or more subprojects. A basic multi-project build contains a root project and a single subproject. This is a structure of a multi-project build that contains a single subproject called app : Example 1.


1 Answers

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.

like image 85
Peter Niederwieser Avatar answered Oct 13 '22 22:10

Peter Niederwieser