Kotlin script: can't login to private repository

Hello Kotlin script fans!
I’ve been able to use without any issue many maven repositories, such as:

@file:Repository("https://dl.bintray.com/jakubriegel/kotlin-shell")
@file:Repository("https://dl.bintray.com/cbeust/maven")
@file:Repository("https://repo.eclipse.org/content/groups/egit")
@file:Repository("https://jitpack.io")

But when I try to use a private Nexus repository, that requires authentication, I can’t find how to provide my credentials.

@file:Repository("https://nexus.mycorp.ca/repository/group")

I have noticed that Repository accepts 2 arguments: options and repositoriesCoordinates

Is there a way to provide Nexus credentials to Kotlin script Repository ?

Thank you!

Which annotation are you using (or maybe, which tool and version)?
I ask because I can’t find the @Repository annotation as you describe. I’m probably looking in the wrong place.

I did find this @Repository annotation that takes a value, an id, and a url. It’s deprecated and so I don’t think it’s the same one you’re using.

1 Like

Hello @arocnies, thanks for your answer.

Here are some examples of usage of this annotation:

As you can see, it’s something official from the kotlin-scriptsub project.

This repository interface can be found in this package: kotlin.script.experimental.dependencies

I could get the decompiled version from my IDE:

package kotlin.script.experimental.dependencies

@kotlin.annotation.Target @kotlin.annotation.Repeatable @kotlin.annotation.Retention public final annotation class Repository public constructor(vararg repositoriesCoordinates: kotlin.String, options: kotlin.Array<kotlin.String> /* = compiled code */) : kotlin.Annotation {
    public final val options: kotlin.Array<kotlin.String> /* compiled code */

    public final val repositoriesCoordinates: kotlin.Array<out kotlin.String> /* compiled code */
}

Looks like it’s this annotation. I’ll take a look a bit later to see if I can’t find how it’s resolving.

If it’s using the MavenDependencyResolver, then it should receive credentials somehow–a quick look seems to show it uses something in the repo coordinates and falls back to environment variables.

Hello,
How would I provide username/password with such a repo declaration ?

@file:Repository("https://nexus.mycorp.ca/repository/group")

repositoriesCoordinates seem to only be a String array.

Thanks

I’m not sure.
It looks like the MavenDepencyResolver checks if the coordinate is a MavenRepositoryCoordinate and pulls the pass/username from that.

But I don’t see where a coordinate like this is created. Here you can see a repo coordinate is being created with the string from the annotation, but that method only creates a generic repo coordinate not a MavenRepositoryCooridate.

Maybe someone else knows where to look for how one uses a @Repository with a MavenRepositoryCoordinate?

Thanks again @arocnies - I’ve also created an issue in kotlin-script-examples since documentation is missing.

@ilya.chernikov has created an issue in YouTrack : https://youtrack.jetbrains.com/issue/KT-43287