this is the source file inside buildSrc. From what...
# gradle
z
this is the source file inside buildSrc. From what I can tell, it should compile, but I get an error that "compile" can't be found
g
Static accessor for configuration available only when a plugin applied with such configuration. In this case use dynamic syntax:
"compile*("your:dependency:1.0")
z
huh, interesting. Is there a particular part of the documentation that goes into more detail on this?
g
Your case little bit more specific, because you use buildSrc, but still follows the rule: static configuration accessors are truly type safe and available only if Gradle knows that a plugin with this configuration is available and generates accessor for it, so it safe to use. But you still can use dynamic syntax for some cases using String.invoke() or just
add
, but it will fail on runtime if such configuration is not available
One more note, instead of writing such functions like in you example, I would better define all those dependencies as an object properties and let user apply them to required configurations, it's more flexible (you can use for example
implementation
or other configurations depending on case), also you do not break safety with this approach
z
that's why I had wound up doing by the time you replied to me. I was just trying to save myself a few keystrokes, anyways
g
Yes, I understand this, but this approach just less safe and flexible, so imo adding dependency to configuration and dependency constants should be separated
One more solution for this: move it to a plugin and apply plugin, so user of this API has true type-safety