If I define a custom version catalog from an artif...
# community-support
s
If I define a custom version catalog from an artifact in my root
settings.gradle.kts
file like
Copy code
dependencyResolutionManagement {
    versionCatalogs {
        create("ortLibs") {
            from("org.ossreviewtoolkit:version-catalog:71.4.0")
        }
    }
}
then what's the correct syntax to depend on an artifacts form that catalog in my project's convention plugins hosted in
buildSrc
?
I'm aware of https://github.com/gradle/gradle/issues/15383 but could not find an example for a custom catalog loaded from an artifact there.
n
I did not try this, but perhaps
Copy code
import org.gradle.accessors.dm.LibrariesForOrtLibs

val ortLibs = the<LibrariesForOrtLibs>()
Alternatively, you can look into this plugin, so you can simply use the regular typesafe accessors: https://plugins.gradle.org/plugin/dev.panuszewski.typesafe-conventions
s
Unfortunately,
LibrariesForOrtLibs
does not resolve. I'll have a look at that plugin, thanks.
n
In order to expose it in the convention plugin, it's important to add the version catalog as a dependency:
Copy code
dependencies {
    implementation(files(ortLibs.javaClass.superclass.protectionDomain.codeSource.location))
}
That seems to work for me in order to make the snippet above function in a convention plugin. I personally prefer the plugin though.
s
Yeah, that syntax alone is too cumbersome, I'll try out the plugin.
v
Or you use the string-y API mentione in that ticket like:
Copy code
versionCatalogs.named("ortLibs").findLibrary("foo")...
👆 2
For my hack-around the same things would be necessary, you need to have that version catalog with that same name in the parent build and in the build that builds the convention plugin, then it should work.
s
I'm eagerly trying to avoid the "and in the build that builds the convention plugin" part 😬
v
Yeah, then you need to either use the string-y api, or that generation plugin. While that generation plugin afair also has some restrictions. For example if your conventions plugin build is an included build and included like you should do - i.e. within
pluginManagement { ... }
it does not work iirc.
n
It does work (that's how we use it), but with the newest version it no longer supports settings conventions plugins. So if you have those, you have to separate them out into a different included build that doesn't apply this plugin.
v
But its docs says it does not work for custom version catalogs as that included build is then built before the settings script is evaluated and it cannot get the information about the declared version catalogs.
s
if your conventions plugin build is an included build
No, I'm using
buildSrc
for my convention plugins.
v
There it might work