This message was deleted.
# community-support
s
This message was deleted.
a
registerIfAbsent() returns a provider for your service, and I guess you want to register your service as an Project extension so it's accessible in the build scripts?
c
yeah, I guess so? I'm really not confident this is designed right, since I'm mostly just trying to add accessible methods to the build scripts
whereas extensions mostly feel like they're used for bagging a bundle of settings properties
a
you probably want to use a ValueSource to contain the git version logic, because otherwise Gradle will complain about Configuration Cache compliance
you could use a build service as a central place for the git logic, but I don't think it brings much over a regular project extension that returns a provider
c
I believe I have removed the problems with configuration cache
I could be wrong
you're probably right, but then how does the extension get the project directory? and what am I supposed to do to expose the method? the access pattern goal is something like
version = ... gitVersion()
a
A build service is useful if you want to wrap some sort of resource, like a connection to a HTTP service, so you can re-use the resource across the build. It's also useful if you want to share a build service with multiple tasks, across the build. So maybe it would be useful in your case, because the version would be accessible in multiple projects..
c
I doubt it's significant either way, I'm sure that the IO for reading .git/refs is pretty negligible
a
true
c
@Vampire suggested the build service 😉
a
and because Project.version hasn't been updated to use the Provider API, I created a wrapper for the version: https://github.com/adamko-dev/kotlin-binary-compatibility-validator-mu/blob/b0509394692942934150cf37fc75e4bbc38d7580/build.gradle.kts#L9-L12
c
so your extension is just a provider?
I mean, I had originally tried to just expose a lambda, but that didn't seem to be possible
a
so your extension is just a provider?
yup
it's possible to add a lambda, but I'd just use a Provider, because hopefully eventually everything will be Provider API compatible
🤣 1
c
looks like java 21 is kind of unhappy with some of (what is I think are suggested access patterns of a build service), this is now a warning and I turn warnings into build errors
Copy code
@Inject
  public GitVersionProvider() {
    this.builder =
      new FileRepositoryBuilder()
        .readEnvironment(SystemReader.getInstance())
        .setMustExist(true)
        .findGitDir(this.getParameters().getProjectDirectory().get().getAsFile());
  }
I have that plugin which uses a build service, you can take a look at it to see how to do functional tests
c
@Adam btw, now working with --configuration-cache, no value source
✨ 1