Is there a way to add an "implementation" dependen...
# gradle
p
Is there a way to add an "implementation" dependency to
gradle-kotlin-dsl-extensions-6.7.jar
to a plugin project? I'm trying to access some extension functions in there like
Copy code
fun DependencyHandler.`implementation`(dependencyNotation: Any): Dependency? =
    add("implementation", dependencyNotation)
m
I think it’s auto-generated during your Gradle build based on the plugins that you’re using. So no, you cannot import it from anywhere 😅
p
ah, that's a bummer
I guess I should re-implement some then 😞
v
Where did you even see this jar file? I get those accessors only as generated files in the Gradle User Home cache
p
I saw it in my IDE in the "External Librairies" collapsible section
and I tracked the functions used in a build.gradle.kts file for the
implementation
function inside a
dependencies
block
v
Ah, I see. But if you look at the details in the module settings, you see the location as
p
and it showed up in there
ahh yeah
v
Interesting, if I navigate to the
implementation
call, it is in
👍 1
p
but I just tried adding that one jar with an
implementation(files(...))
dependency to my plugin project, and still can't reference those extension functions
yeah that's how I tracked in down
v
Anyway, if you use pre-compiled script plugins with the Kotlin DSL, you can also use those accessors, they are also there generated. If you write the plugin as normal Kotlin file, then not. In that case you probably have to just define them yourself, they are one-liners after all.
p
yeah that's what I did
Copy code
fun DependencyHandlerScope.implementation(dependencyNotation: Any): Dependency? =
  add("implementation", dependencyNotation)

fun DependencyHandlerScope.testImplementation(dependencyNotation: Any): Dependency? =
  add("testImplementation", dependencyNotation)

fun DependencyHandlerScope.testRuntimeOnly(dependencyNotation: Any): Dependency? =
  add("testRuntimeOnly", dependencyNotation)
not too bad
but I wouldn't want to have to reimplement the world if I need other stuff 😛
I assumed there was a way to import those
g
You cannot "import" them, because they generated only if those configurations are exist, so it truly type-safe way, those extensions are not
I think suggested by Björn precompiled script plugins is the best way to develop Gradle plugins in Kotlin, you are getting much more dsl improvements than using raw gradle APIs as in case of Java/Groovy plugins
p
how do you use those?
v
I wouldn't say "best", it depends on the actual needs
Some things are maybe nicer to do with "raw" Java, Groovy or Kotlin plugins
g
Yeah, maybe not the best, but if you have experience with build.gradle configs, it looks much more natural
v
How you use those is basically you have
foo.gradle.kts
files in your Gradle source set and you apply the
gradle-dsl
plugin.
g
Depends on complexity of the plugin of course
v
The
foo.gradle.kts
files are nearly identical to what you would write in a normal build file. One notable difference is, that you must not have version numbers at applied plugins but define those as dependencies in the build script of the plugin project
p
I see
v
The optional package statement in the file plus the name in front of
.gradle.kts
gives the plugin id
p
I was trying to write a plugin in pure kotlin
but also use some extensions from gradle-kotlin-dsl
p
I'll try and see if that thing fits my needs though
and then, in IntelliJ I assume you have to add your script to your standalone scripts to get some autocompletion?
v
No
It will just work fine