Hello, I am trying to add to my buildSrc file the ...
# gradle
j
Hello, I am trying to add to my buildSrc file the dependency for
org.gradle.kotlin.dsl
but I can't find it.
Or a way to access to the implementation, testImplementation, etc. accessors without using them as string
e
Have a read at https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin You don’t “depend on the kotlin-dsl”, instead you apply the plugin documented above.
j
Hi @eskatos, I know it but I am creating my own plugins inside
buildSrc
, then I got
implementation
cant be used directly so I have to create my own function directly to use it. This can be tedious because there are a lot of functions, even I have two different
implementation
...
Copy code
fun DependencyHandler.implementation(dependencyNotation: Any): Dependency? {
    return add("implementation", dependencyNotation)
}
e
if you want to get the type safe accessors generated you need to use the
plugins {}
block to apply other plugins
assuming the screenshot above is from a precompiled script plugin
j
But if I use the
plugin {}
block then later it can't compile where I use
Copy code
plugins {
    MyPlugin
}
e
it should work if your plugin ID is
MyPlugin
ah no, for plugins that are siblings, you need to spell the ID
Copy code
plugins {
    id("MyPlugin")
}
j
I have not added a id directly, I only put the code of the screenshot inside MyPlugin.gradle.kts
e
I guess we’re not talking about the same thing. Sorry for the confusion. In your screenshot above, try replacing
Copy code
apply(plugin = Plugins.androidLibrary)
apply<AndroidBaseSetupPlugin>()
apply<AndroidBaseAppSetupPlugin>()
by a
plugins {}
block that applies the same plugins (need to be by plugin ID) then you’ll get the type safe accessors to e.g.
implementation()
j
Yeah, I got the problem, I cant use Plugins.androidLibrary as id(...) if I put the string directly it works. I will have to create it as ProjectDependencySpec to add to the plugins block, thank you 🙂
e
Happy to help!
j
@eskatos I am having another use case where I haven't any plugin so I can access to dependencies block but not to every function
e
Type safe accessors aren’t available for all use cases, that’s expected. See https://docs.gradle.org/current/userguide/kotlin_dsl.html#type-safe-accessors for the list of use cases and how to deal with their absence.
👍 1