Overview
This can have unwanted side effects IMHO.
The proper solution is to have Go 1.22 in 15.6. You can send an SR for that.
Caddy 2.8.4 requires Go 1.21, while Caddy buildable artifacts require 1.22, this seems like an upstream problem to me. I'm also not sure what benefits we get from buildable artifacts, there are other ways to inject the version into a Go package.
Injecting the version manually seemed to require a bigger patch, or anyway I was not able to understand how to do it. We might as well wait until this bug is fixed in golang (likely never) or the caddy git repository is reworked.
To my understanding, now that 15.6 is released it would not allow to bump major version of packages on which many others depend on.
I superseded your request, take a look, and if you are happy add a comment and I'll merge it.
Sure, it works ok.
I was missing -ldflags '-X github.com/caddyserver/caddy/v2.CustomVersion=v%{version}'