Jin
Jin

Reputation: 890

How to list gradle modules on command line?

I have a project directory that looks like:

MyProject
├── *app*
├── build
├── build.gradle
├── gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── keystore.properties
├── local.properties
├── *module2*
├── *module3*
└── settings.gradle

where the modules have been highlighted.

I know I can build a task of a particular module / subproject by doing:

./gradlew module:assemble

and I can get all tasks with:

./gradlew tasks

But how can I get the names of the modules themselves (i.e. app, module2, module3)?

Upvotes: 8

Views: 8565

Answers (2)

Dan Tanner
Dan Tanner

Reputation: 2444

projects is the task you're looking for. e.g.:

> ./gradlew -q projects

------------------------------------------------------------
Root project 'my-project-name'
------------------------------------------------------------

Root project 'my-project-name'
+--- Project ':apps'
|    \--- Project ':apps:api'
\--- Project ':libs'
     +--- Project ':libs:common'
     +--- Project ':libs:http-client'
     +--- Project ':libs:http-server'
     \--- Project ':libs:test-common'

To see a list of the tasks of a project, run gradlew <project-path>:tasks
For example, try running gradlew :apps:tasks

Upvotes: 16

Ozbolt
Ozbolt

Reputation: 133

This is not an optimal solution, but before we get a proper one may be useful. Running this command

./gradlew tasks --all

You will get all tasks for all modules, so to get all modules that can be assembled, you can use this oneliner:

./gradlew tasks --all | grep ":assemble" | cut -d: -f1 | sort -u

Upvotes: 8

Related Questions