Gradle IvyPublishing with custom group ID derived from the project's group name

I am writing a custom Ivy publishing plugin that creates an ivy publication with a custom organisation name = project’s group + branch name. branch name is a constant, so it can be hardcoded in the publication closure but I need the project’s group before the branch name

Project’s group is declared in build.gradle file.

project.publishing.publications.create('abc', IvyPublication) {
    organisation = project.getGroup() + ".branchA"
    artifact (genArchiveTask) // genArchiveTask is a simple Zip task that creates a zip file.
}

But when I run the corresponding publish task, the project group is empty. I cannot hardcode the group ID as it is not same accross the projects. Is there a different way to do this?

Unfortunately IvyPublication#organisation and Project#group both are primitive Strings and not Propery<String> so that they could be wired together.

Hopefully with Gradle 9 and the great Property / Provider migration this will change.

In the meantime you could try to use the lazy register instead of the eager create and be lucky. Depending on who and when realizes the publication the user might have had a chance to set the group.

If not, you could use the bad practice afterEvaluate to do that setting and be lucky.
Depending on where the user sets the group it might now have been set to its final value.

If you control the consumer projects, then you could do much easier, assuming the group is a constant in those projects.
Don’t set it in code, but in the gradle.properties file. (The version too)
Then it is already there for any plugin or code that wants to read it.