Want to create new project and add some files using custom plug-in, but init task skipped if -b specified

Pretty new to gradle. Using 3.4. I need to allow developers to, in one step, create a new java-application project and then prepopulate the new project with some additional files. I have been working on a custom task and plug-in and I was hoping to leverage the init task (as in “gradle init”).

I have a setup.gradle file that refers to my plug-in and resides in a separate gradle project that is outside the directory where I want to create the new project. The plug-in is defined in a .groovy file under buildsrc in that other project. In the plug-in I make my custom task depend on the automatically-included init task.

When I run “gradle -b /other-dir/setup.gradle myInitTask” gradle starts but then skips the init task:

The build file 'setup.gradle' already exists. Skipping build initialization.

and adding --info to the command line reveals this:
Skipping task ':init' as task onlyIf is false.

I suspect that the init task sees that it is processing a file and therefore skips the task, perhaps assuming that the file is from the project being created.

Any suggestions for working around this or accomplishing this in an entirely different way?

Answering my own question…

One promising approach seems to be to use an init script via -I rather than a build script via -b for populating the new project. Because I will want to provide my own skeleton Java app (rather than the App.java provided by the init task) I might not rely on the built-in init task after all, but using an init script might turn out to be better anyway.