November 11, 2009

Gradle Goodness: Changing the Project Name

By default the name of our Gradle project is the name of the directory the project is created in. We can check this by running the following command:

$ gradle -r | grep name
name: project

The first place we think of to change the project name is build.gradle, because that is also the file we can change for example the version property of our project:

name = 'newProjectName'

When we run gradle we get an error:

* What went wrong:
A problem occurred evaluating root project 'project'.
Cause: Cannot set the value of read-only property 'name' on root project 'project'.

So what can we do? We must create a file settings.gradle and set the property rootProject.name:

rootProject.name = 'newProjectName'

We can check the name of our project has changed by running the following command again:

$ gradle -r | grep name
name: newProjectName