Auto-prepend rootProject.name to any subproject name

I experimented with different approaches to auto-prepend the root-projectname to any subproject name.

Let me show what I have: a project / directory called “myProj”

/build.gradle
/settings.gradle
/module1/…
/module2/…

with settings.gradle containing

include 'module1'
include 'module2'

or

include ':module1'
include ':module2'

What happens:

  • the default behaviour is: the rootProjectname is the same as it’s directory is named, unless you specify the name in settings.gradle rootProject.name = 'myProj'
  • The modules are called as their directories, unless you specify a different name in /settings.gradle per project(':module1').name = 'differentMod1Name'
  • all artifacts are typically called as their project / subproject are named

What I want to archive:

  • any subproject is still settled in a directory just called “moduleXY”
  • their name should auto-prepend by the name of the rootProject

i.e. in this example above:
I expect to get artifacts for myProj-moduleXY

yes, I can define it line by line for each subproject, but this is not the point neither practical if there are lots of
another use-case that have some charms to get it dynamically would be: someone forks of the project but just renames the rootProject, he should just be forced to change one line

Any ideas?! Or it is just impossible?!

Thanks for your input
~Marcel

I use this approach in my settings.gradle

def prefix(prefix) {
    rootProject.name = prefix
    rootProject.children.each { it.name = "${prefix}-${it.name}" }
}
include 'core',
        'api',
        'client'
prefix('mylib')

directory structure is like

mylib/
    api/
        build.gradle
    client/
        build.gradle
    core/
        build.gradle
    build.gradle
    settings.gradle

I think this is the same as what you’re looking for

mhh…yeah, indeed I thought I have tried this too and I stumbled to some sort of “prefix()” is not defined error … some sort of user error I think ,)
works fine and as expected.

Thanks
~Marcel