Hello all, hopefully this is a simple question for...
# community-support
m
Hello all, hopefully this is a simple question for someone. In
settings.gradle.kts
, I'm using the following to get the value of
myVersion
from
gradle.properties
.
Copy code
val myVersion: String by settings
How do I do the same from
buildSrc/settings.gradle.kts
?
v
No difference. The "problem" is, that
buildSrc
is an own build that does not use the same
gradle.properties
file and the properties are not propagated to the
buildSrc
build as it is an own build that "just happens" to build before your main build. If you want to have a central place to define versions, I recommend you use a version catalog instead, you can then in the
buildSrc
build to use the same version catalog as the main build.
m
I have a version catalog but this version number (
micronautVersion
) is used as follows in the
settings.gradle.kts
Copy code
val micronautVersion: String by settings

dependencyResolutionManagement {
    repositories {
        mavenCentral()
    }
    versionCatalogs {
        create("mn") {
            from("io.micronaut.platform:micronaut-platform:${micronautVersion}")
        }
    }
}
v
Ah, I see. And yeah, my bad, in the settings script you of course cannot use the version catalog unless you parse it yourself
And you need the MN version catalog in the
buildSrc
build?
m
Yes, to provide common dependencies and plugins in a convention plugin.
v
How do you use the version catalog in your convention plugin?
m
As an example, I was hoping to have
Copy code
dependencies {
    implementation(mn.micronaut.serde.jackson)
...
}
in my convention plugin.
v
That's not as easy as you imagine unfortunately. If you have a version catalog in the
buildSrc
settings script, that is for the
buildSrc
build scripts, not for the things you build inside the project like conventions plugins. For that you would need my hack-around, and even with that, it would not work for plugins but only for normal dependencies. Maybe you should consider using the string-y
VersionCatalogsExtension
in your convention plugins, so something like
versionCatalogs.findCatalog("mn").findLibrary("micronaut-serde-jackson")
or what the syntax was. Then you also do not need the version catalog in the
buildSrc
build.
For the plugin dependencies in
buildSrc/build.gradle.kts
on the other hand you could use them, but maybe you should just duplicate the mn version to both
gradle.properties
, the main build one's and the
buildSrc
build one's
m
Thanks for the explanation @Vampire. I appreciate you taking the time.
👌 1