Hi everyone! I am making some project which has a ...
# gradle
j
Hi everyone! I am making some project which has a JVM backend module, a shared multiplatform Common module and a multiplatform Frontend module. I wanted to use the buildSrc to define my dependencies, and chop it into nice methods like
Copy code
fun DependencyHandlerScope.implementKtorServer(flavor: String = "") {
            implementation(ktor(Serialization), flavor)
            //.... others...
            implementation(ktor(AuthJwt), flavor)
        }
In this way, I can easily call this from my build.gradle.kts for the backend module
Copy code
dependencies {
    implementKtorServer()
    // ... other things
This is because the dependencies in a Gradle file give you a DependencyHandlerScope context. However, with multiplatform, like this:
Copy code
val commonMain by getting {
            dependencies {
                // ... stuff
You have a 
KotlinDependencyHandler
 context. So my question is: How can I make an extension function in my buildSrc module on a KotlinDependencyHandler? I tried to pull in some kotlin gradle plugin dependencies in my buildSrc/build.gradle.kts but no luck. For now, it looks like this:
Copy code
plugins {
    `kotlin-dsl`
}
repositories {
    jcenter()
}
And 
KotlinDependencyHandler
  is until now unresolved 😞 Does anyone know what I could do here?
a
You can declare dependencies in the standard
dependencies{}
block for multiplatform projects too, using
commonMainApi
,
commonMainImplementation
etc configurations. But in build.gradle.kts, you need to quote the configuration names as they are not declared early enough for the accessor generation
👍 1
Failing that, or if you need to configure more than dependencies, you may be stuck making the platform plugin an implementation dependency of buildSrc itself (at which point that will take over fixing which plugin version you’re using)
j
That is interesting 🙂 I'll have a look there
thanks!
Copy code
dependencies {
    implementKtorClientCommon("commonMain")
}
This indeed works
Copy code
private fun DependencyHandler.implementation(dependency: Any, flavor: String) {
    val configurationName = flavor.takeIf { it.isNotBlank() }?.let {
        "${it}Implementation"
    } ?: "implementation"
    add(configurationName, dependency)
}
@araqnid the commonMainImplementation and such work fine, but other configurations (like jvmMain) do not exist yet as you mentioned. Any idea how I should quote it? I tried `'"`` quotes around
jvmMainImplementation
and only around the
jvmMain
part but it fails
a
if you’re already passing the configuration name as a string (by calling your DependencyHandler.implementation extension with a “jvmMain” parameter etc) then it’s not quite that problem. But it might simply be that you need to move these
dependencies{}
to after the kotlin mp configuration in the build file
j
@araqnid the moving it to the bottom certainly worked its magic and when I list all configurations all of them show up and I can use it like that 🙂 thanks!
👍🏻 1