This message was deleted.
# community-support
s
This message was deleted.
a
can you show some code of what you’ve tried, and the errors of what doesn’t work? Are you writing code in a
build.gradle.kts
file, or are you writing a plugin? What variables do you want to operate on?
s
so, let's say in a conventions gradle plugin...i set the following:
Copy code
object SreichTestMap {
    val mapThing = "a" to "z"
}
it's then my expectation that i can apply the plugin to say, a different project and right in my build.gradle.kts i can start typing println(SreichTestMap.mapThing), and otherwise operate on it type safely
i haven't found in the docs how they are able to type safely share and expose elements like that
a
your example should Just Work™, so long as you apply the convention plugin to a build script What will happen is your plugin will get compiled into a JAR, which will also contain
SreichTestMap
. When you apply your plugin to a project, then the JAR will be applied to the build script’s classpath. Since
SreichTestMap
is public, then it will be accessible in the build script.
s
Ya know, that's what I thought but it was failing. I'll try to reproduce it next week
That would be the recommended way to do this, right?
Versus say, extra properties which would be not discoverable or type safe
a
it kind of depends, but the best way is usually to create a custom extension that uses Provider API compatible types https://docs.gradle.org/8.1.1/userguide/implementing_gradle_plugins.html#modeling_dsl_like_apis
but yeah, extra properties typically aren’t very good, I avoid using them
👆 1
s
Okay interesting,I'll take a read! Thanks for the link
v
Yep, extra properties are almost always just a work-around for not doing it properly. 😄