Preferring snapshot versions of equal branch names

we use maven-style snapshot versions in our project.

Is it possible to implement a rule to prefer versions with the same branch names over the masters versions (prefer 0.0.1-feature-foo-SNAPSHOT over 0.0.1-SNAPSHOT if on branch feature-foo)?

Gradle does not know anything about branches.
Branches are a VCS feature Gradle is not aware of itself.
If you want that, you need to implement it yourself.
The regular way is to define that version if you want to have it.

Yes I see that, but getting the current branch name is easy for me. Whats hard is, to tell gradle to use the branch snapshot version (0.0.1-feature-foo-SNAPSHOT) if it exists and the master version otherwise.

I don’t know what would be the best way to implement that rule. Looking at component selection for example, I could reject the master version if I would now that the branch version exists. Is there a way to check for some version during component selection?

Or is a different way better/easier?

I see.
I guess you have at least two options that are both not optimal.

If you know the URL of the repository where those versions would be published, you could try to download the POM for the branch to see whether it is there or not.

Or you could let Gradle do dependency resolution to figure out whether it is there, for example using an artifact resolution query like

if (
        .forModule("group", "module", "0.0.1-feature-foo-SNAPSHOT")
        .withArtifacts(MavenModule::class, MavenPomArtifact::class)
1 Like

Thats for your reply. I did not yet find the time to come back to that topic, but your suggestion looks like it’ll help there.