Initialize a subproject within a root project from the command line

Newbie here. I’m looking for a built-in command that initializes a subproject within an existing root project. The command should also generate the skeleton for the subproject and allow users to specify the project parameters such as the name of the subproject, the project type, the choice of test framework, etc. (much like what gradle init does).

The issue with gradle init is that it initializes a root project, not a subproject. The created project will have its own settings.gradle file and a subproject called app, which doesn’t fit my use case. The workaround is of course to either:

  1. Move the app directory out of the created project directory, place it in the directory containing my actual root project, and then delete directory created by gradle init
  2. Run gradle init with the --type basic option and then manually create the subproject’s directory structure.

(1) is a pain and (2) defeats the whole purpose of the initialization process.

There is no such built-in functionality.
But actually adding a module is just adding the include line in the settings script and then having what you need in the build script of that new subproject.
And optimally you use convention plugins already and thus just apply one plugin in that build script.

Thanks for your response.

So if I create a directory for my subproject (let’s say app2) and then add a build script app2/build.gradle.kts with the following contents:

plugins {

repositories {

dependencies {

After that, as long as I add include("app2") into the settings.gradle.kts file in my root project, gradle will automatically create the directory structure based on the plugin specified in the build script (in this case, it’s java-application) inside app2?

Is that how this works?

No, Gradle does not create any directory structure for you.
It could not actually guess what it should create anyway.
There are various possible directories where you could have things that are then considered.
You just create the things you need yourself.
If you use a proper IDE like IntelliJ IDEA, it will also help.
If you have the application plugin applied any your project in-sync, then when you say New Directory it will for exmaple suggest src/main/java and so on.