In buildSrc, i add a deps.gradle.kts or deps.kt as a gradle plugin. every function in it has a dependency block so i can use the function to add a couple of dependencies.but the implementation key word is error(below in the picture)
oh, it’s my fault, i didnt clean cache to let the kotlin-dsl-precompiled-script-plugins generate new accessors. when i cleaned cache and build, it’s ok
The ...accessors._a31a802bb49e4298771372939c4853ad... does not work well and is a big error your IDE might have added through automatically adding imports.
Using those accessors with hash in them is always the wrong thing to do, as the hash will change as soon as there is any change in the classpath.
In a precompile script plugin the accessors will be available if you apply a plugin that adds those configurations. If not, or you are in a .kt plugin, you do not have access to the accessors and need to get the configurations differently like
val implementation by configurations.existing
dependenices {
implementation(...)
}
or similar.
If all you want to achieve is adding several dependencies as one bunch, I’d recommend you do not use any plugin but simply use a bundle in a version catalog which is exactly designed for that use-case.
i’m not using version catelog bundle because all dependenies in one bundle could use one configuration like implementation. while a function define a dependency block could add ksp,testImplementation dependencies.(i’m lazy, i don’t want to add one more line for testImplementation or others)
Then the quesion is:
the val implementation by configurations.existing exists in plugin-name.gradle.kts as it’s in gradle context
but in my deps folder’s deps.kt file, the configurations does not exist. so i have to use import gradle.kotlin.dsl.accessors._2a9c0e03359a4d9854f3ba65e889cbe0.implementation to access implementation.
i’m lazy, i don’t want to add one more line for testImplementation or others
Sure, do whatever pleases you, you have to live with the consequences.
For example if you change a single version, the classpath of all tasks in your build will change and thus all tasks will be out of date.
If you would use a version catalog in a TOML file this would not be the case, as they are specifically designed to avoid such things.
You can still keep the versions or even coordinates in the version catalog but have such helper functions that use the entries in the version catalog to have the best of both approaches.
so i have to use import gradle.kotlin.dsl.accessors._2a9c0e03359a4d9854f3ba65e889cbe0.implementation to access implementation .
No, you cannot use such imports, they will constantly bite you in the ass. Never ever everever use them. add("implementation", ...) is what you are after in the .kt file.