Hey, long time not tried Kotlin scripts, do we sti...
# scripting
Hey, long time not tried Kotlin scripts, do we still need kscript for basic scripts with dependencies?
You can do most of the things with
. Kscript is still useful to package your scripts if you want to distribute them
☝️ 1
Oh, nice. Can you define a custom maven repository? Where is the current implementation documented?
Copy code
This is not up to date, nothing about *.main.kts
But it shows you the repository annotation
It still talks about making a whole gradle project, which isn’t scripting to me, a script is a self contained file with a shebang and nothing else, if I want to do a whole gradle project I’m doing a normal kotlin app, kscript was good and the *.main.kts thing seems great in that regard
The annotation is the same though 😉
I just need to see how to put credentials in my repository definition and I should be set, thanks 😄
👍 1
It does not seem to be able to find the jvm dependency of a multiplatform lib by itself but other than that, looks good to me!
Found the way to put credentials in a youtrack issue though. This needs proper documentation, but I guess it’s experimental
👌 1
Mind sharing the way here for people discovering this thread by search?
Ah, looking in the source it is probably just including them in the url like usual
Nope, it doesn’t work in the URL (for me). It relies on the normal Maven/Gradle env though, so you should probably just define the credentials in
as usual, but if you want to do the bad thing of putting them right there in the script like me, you can use the
parameter of the annotation, as described here: https://youtrack.jetbrains.com/issue/KT-27701#focus=Comments-27-5323682.0-0 (you can use
once for
annotation, don’t need to use it on each dependency if you have multiple) I recommend reading this entire issue comments thread, it’s interesting.
Ah, I see.
I looked at the wrong
Right now it’s missing direct multiplatform dependency support and maybe global suspend, but other than that it seems to work great. I have an executable
file and I just need to have
installed on my machine for it to run, nice
👌 2
missing direct multiplatform dependency support
I filed this issue some time ago. Doesn't look like it's coming any time soon. But adding
usually works so at least there's an easy workaround
as a short-term workaround, the library can modify its POM to point to the JVM artifact so that non-GMM consumers get it (since all non-JVM consumers are going to be relying on GMM anyway, this should be safe)
something along the lines of
Copy code
publishing {
    publications {
        val jvm = getByName<MavenPublication>("jvm")
        getByName<MavenPublication>("kotlinMultiplatform") {
            pom.withXml {
                val root = asNode()
                val dependencies = ((root["dependencies"] as NodeList).firstOrNull() as Node?)?.apply {
                    for (child in children().toList()) remove(child as Node)
                } ?: root.appendNode("dependencies")
                dependencies.appendNode("dependency").apply {
                    appendNode("groupId", jvm.groupId)
                    appendNode("artifactId", jvm.artifactId)
                    appendNode("version", jvm.version)
                    appendNode("scope", "compile")
in its
👍 1
Would be nice for the Kotlin Gradle plugin to do this actually...