Set `gitTagToVersionNumber` per-project in a multi-project build
In a project I am working on we have a mono-repo that includes various subprojects that are versioned and released separately. We'd like to switch to using sbt-git for these versions, so that for example we could use tags like Project1-vA.B.C to get the version of Project1 and Project2-vX.Y.Z to get the version of Project2.
However, it seems there is no convenient way to change the gitTagToVersionNumber setting for different projects within a multi-project build because the setting exposed by the plugin is explicitly scoped to ThisBuild. To get this to work I had to essentially copy the version setting into my build definition, but modify it to refer to the com.typesafe.sbt.SbtGit.GitKeys.gitTagToVersionNumber directly, instead of git.gitTagToVersionNumber which is scoped to ThisBuild.
I wonder if there's a way to make this work more cleanly without otherwise changing the way the plugin works by default. In particular, it seems to me that the setting implementations for things like version should refer to the underlying keys and let scope delegation handle the rest, rather than referring to explicitly globally-scoped keys. However, I'll admit that scoping and delegation can be confusing so this might have some downside I can't see.
Heartily seconded!
There's some commonality between this and the issue I raised back in June (#133) - I have been wanting exactly the same thing but was initially focused on the first blocker.
@maffoo would you be able to share some more details (perhaps an example?) of your workaround in the meantime?
@oliverlockwood I literally had to just copy the version setting code from the plugin into my build and modify it slightly to scope it to the project instead of ThisBuild. For various other reasons, I've actually switched to just shelling out to git instead of using this plugin at all. Sadly...
In particular, it seems to me that the setting implementations for things like
versionshould refer to the underlying keys and let scope delegation handle the rest, rather than referring to explicitly globally-scoped keys. However, I'll admit that scoping and delegation can be confusing so this might have some downside I can't see.
I very much agree with you. The "downside" is that sbt's settings/scopes just don't work like that. I've filed that issue as https://github.com/sbt/sbt/issues/2899.
I think we could resolve this issue by defining a new opt-in GitPerProjectVersioning AutoPlugin which defines things in project scope instead of build scope, then you can redefine gitTagToVersionNumber per-project. Pull requests welcome.