Executing a kotlin -script.kts with a dependency from github

Viewed 1144

I am aware that *.kts scripts can include a dependency like this:

#!/usr/bin/env kscript
@file:DependsOn("com.domain.project:name:1.0-SNAPSHOT")

I created a small library to process different text snippets and uploaded it on github.

Is it possible to use this library as a dependency within a kotlin script without going through mvnRepository or something similar?

something like this for example:

 #!/usr/bin/env kscript
 @file:DependsOn("com.github.username.project")
1 Answers

I was not able to find a method of requesting the dependency from the repository or the direct url of a jar file.

I was however able to use jitpack on top of my regular github repository. Unfortunately, pointing to the master branch did not work for me, but creating a release seem to work just fine.

The resulting boilerplate looks like this:

#!/usr/bin/env kscript

@file:MavenRepository("com.github.username:repo:1.0.0", "https://jitpack.io")
@file:DependsOn("com.github.username:repo:1.0.0")

import repo.MyLibrary

fun useLibrary(){
    val library = MyLibrary()
    library.use()
}

Where com.github.username is the personal github account, repo is the repository and 1.0.0 is the release version tag.

Related