I am interested in potentially developing a Settings plugin that customizes the way a Version Catalog is created. I am only interested in customizing the behavior for when BOM coordinates are passed in, for example
versionCatalogs {
create("bomLibs") {
from("io.micronaut:micronaut-bom:3.3.1") // custom handling for this type
}
}
How can I use Gradle’s built-in resolution capabilities to fetch the artifacts for that dependency, in particular the pom file? If this were a Project plugin, I could do project.dependencies.createArtifactResolutionQuery()... to fetch the files, but I don’t see a straight forward path of doing that from the Settings object.
I’m not 100% sure, but I don’t think you can leverage the dependency resolution mechanism of Gradle in a settings script.
Version catalogs are just a “dumb” list of coordinates and versions that you can type-safely access in the build script and that you can change without invalidating all up-to-date state.
If you really need to do some resolution there, you probably need to either use some internals if possible at all, or depend on some library that can do the dependency resolution. But this also then needs precious time that will done on every build invocation and so on, so you should really thing three times whether you really want and need that.
already works, I just want to handle the version catalog creation differently. In Micronaut’s case they provide micronaut-bom-3.3.1.toml at the coordinates that Gradle finds at build time and generates the catalog from. So the plugin wouldn’t be doing anything that doesn’t happen already, just differently. The resolution logic I need must exist somewhere for that to work, but I think you’re right that it’s currently internal
Yeah, what I meant is that you cannot use it in a supported way from there.
Under the hood, the normal resolution dependency infrastructure is used of course.
But I don’t even know whether you could use it with internals.
Why do you actually want to customize it?
What do you want to achieve?
I think the Version Catalog functionality falls short with respect to how BOMs are handled. I submitted a feature request on GitHub for how I thought it could work, but the team turned it down. I was going to try and build my idea out as a plugin. The thought process would be to auto-generate a catalog from a BOM
I’m sorry, but I still don’t get what you mean.
Micronaut provides a version catalog at those coordinates, so you can just define the version catalog as you showed, what else do you need?
Yes, Micronaut does but many projects do not (spring, mockito, jackson, etc). I wanted to try and create a plugin which generated a TOML / Version Catalog based on the POM alone, if the TOML was not present
I see.
Well, many BOMs are not even meant to be used like a version catalog.
But well, you could maybe just not use dependency resolution, but simply download from a given URL?
Other than that, you can probably use the library that allows parsing POMs, org.apache.maven:maven-model:3.8.5 to then parse and process the BOM.
Yea URL would work, I was hoping to get the private repo / credential management out of the box. I can start with the URL approach as a POC and if I can get that working I will try and get more advanced resolution integrated. Thanks for the help