I want to use the theese Accessors (implementation...
# gradle
m
I want to use the theese Accessors (implementation, kapt, testImplementation, ...) in my buildSrc, but the extension-Functions are not there. Am i missing an gradle import or what could be wrong here? When i copy this block of code into a Utils file inside buildSrc everything works.
Copy code
/**
 * Adds a dependency to the 'implementation' configuration.
 *
 * @param dependencyNotation notation for the dependency to be added.
 * @param dependencyConfiguration expression to use to configure the dependency.
 * @return The dependency.
 *
 * @see [DependencyHandler.add]
 */
fun DependencyHandler.`implementation2`(
    dependencyNotation: Provider<*>,
    dependencyConfiguration: Action<ExternalModuleDependency>
): Unit = addConfiguredDependencyTo(
    this, "implementation", dependencyNotation, dependencyConfiguration
)
But that can't be the solution or? This is my current buildSrc/build.gradle.kts:
Copy code
repositories {
    google()
    mavenCentral()
    maven("<https://jitpack.io>")
}

plugins {
    `kotlin-dsl`
}

dependencies {
    implementation("com.android.tools.build:gradle:7.2.1")
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
}
v
Those accessors are generated only for Kotlin DSL build scripts and precompiled script plugins where a plugin is applied in the
plugins
block that ensures those are actually available at runtime. If you want to use them in a "normal" Kotlin file, you need to define the accessor yourself or not use such accessors, but work with them
String
based. But besides that, I'd recommend you use a version catalog instead of such a
Dependencies
class.
m
Okay. So copy-pasting theese functions is the "right" approach
v
Well, if you ask me, the "right" approach is to use a version catalog instead. 🙂
But yeah, you can copy that method of course.
m
Okay. I will look into that. Thanks for your help!