https://kotlinlang.org logo
Title
j

Javier

03/25/2020, 3:10 PM
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

eskatos

03/25/2020, 4:58 PM
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

Javier

03/25/2020, 5:10 PM
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
...
fun DependencyHandler.implementation(dependencyNotation: Any): Dependency? {
    return add("implementation", dependencyNotation)
}
e

eskatos

03/25/2020, 5:11 PM
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

Javier

03/25/2020, 5:12 PM
But if I use the
plugin {}
block then later it can't compile where I use
plugins {
    MyPlugin
}
e

eskatos

03/25/2020, 5:12 PM
it should work if your plugin ID is
MyPlugin
ah no, for plugins that are siblings, you need to spell the ID
plugins {
    id("MyPlugin")
}
j

Javier

03/25/2020, 5:13 PM
I have not added a id directly, I only put the code of the screenshot inside MyPlugin.gradle.kts
e

eskatos

03/25/2020, 5:16 PM
I guess we’re not talking about the same thing. Sorry for the confusion. In your screenshot above, try replacing
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

Javier

03/25/2020, 5:17 PM
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

eskatos

03/25/2020, 5:18 PM
Happy to help!
j

Javier

03/25/2020, 5:32 PM
@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

eskatos

03/26/2020, 8:43 AM
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