'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)?
Solution 1:[1]
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
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ozbolt |
| Solution 2 | Dan Tanner |
