# Kotlin script: can't login to private repository

**URL:** <https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688>\
**Category:** Support\
**Created:** [October 27, 2020, 5:57pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688 "2020-10-27T17:57:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthonydahanne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/anthonydahanne/32/5212_2.png) [@anthonydahanne](https://discuss.kotlinlang.org/u/anthonydahanne)\
**Post date:** [October 27, 2020, 5:57pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/1 "2020-10-27T17:57:05Z")

</div>

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

```auto
@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.

```auto
@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!

---

<div class="post-metadata">

**Author:** ![arocnies](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/arocnies/32/5143_2.png) [@arocnies](https://discuss.kotlinlang.org/u/arocnies)\
**Post date:** [October 27, 2020, 6:25pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/2 "2020-10-27T18:25:37Z")

</div>

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](https://github.com/JetBrains/kotlin/blob/0ff45f1cc445d3bc9472fac524279bb1722cc7c1/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/annotations.kt#L29) 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.

---

<div class="post-metadata">

**Author:** ![anthonydahanne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/anthonydahanne/32/5212_2.png) [@anthonydahanne](https://discuss.kotlinlang.org/u/anthonydahanne)\
**Post date:** [October 27, 2020, 6:30pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/3 "2020-10-27T18:30:28Z")

</div>

Hello @arocnies, thanks for your answer.

Here are some examples of usage of this annotation:

> <https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/main-kts/scripts/kotlin-shell.main.kts>

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

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

I could get the decompiled version from my IDE:

```auto
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 */
}

```

---

<div class="post-metadata">

**Author:** ![arocnies](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/arocnies/32/5143_2.png) [@arocnies](https://discuss.kotlinlang.org/u/arocnies)\
**Post date:** [October 27, 2020, 6:41pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/4 "2020-10-27T18:41:33Z")

</div>

Looks like it’s [this annotation](https://github.com/JetBrains/kotlin/blob/master/libraries/scripting/dependencies/src/kotlin/script/experimental/dependencies/annotations.kt#L31). 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](https://github.com/JetBrains/kotlin/blob/master/libraries/scripting/dependencies-maven/src/kotlin/script/experimental/dependencies/maven/MavenDependenciesResolver.kt), then it should receive credentials somehow–a quick look seems to show it uses [something in the repo coordinates](https://github.com/JetBrains/kotlin/blob/master/libraries/scripting/dependencies-maven/src/kotlin/script/experimental/dependencies/maven/MavenDependenciesResolver.kt#L97) and falls back to environment variables.

---

<div class="post-metadata">

**Author:** ![anthonydahanne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/anthonydahanne/32/5212_2.png) [@anthonydahanne](https://discuss.kotlinlang.org/u/anthonydahanne)\
**Post date:** [October 27, 2020, 6:51pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/5 "2020-10-27T18:51:34Z")

</div>

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

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

```

`repositoriesCoordinates` seem to only be a String array.

Thanks

---

<div class="post-metadata">

**Author:** ![arocnies](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/arocnies/32/5143_2.png) [@arocnies](https://discuss.kotlinlang.org/u/arocnies)\
**Post date:** [October 27, 2020, 7:27pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/6 "2020-10-27T19:27:23Z")

</div>

I’m not sure.  
It looks like the MavenDepencyResolver checks if the coordinate is a [MavenRepositoryCoordinate](https://github.com/JetBrains/kotlin/blob/0ff45f1cc445d3bc9472fac524279bb1722cc7c1/libraries/scripting/dependencies-maven/src/kotlin/script/experimental/dependencies/maven/MavenDependenciesResolver.kt#L96) and pulls the pass/username from that.

But I don’t see where a coordinate like this is created. [Here](https://github.com/JetBrains/kotlin/blob/master/libraries/scripting/dependencies/src/kotlin/script/experimental/dependencies/annotations.kt#L47) you can see a repo coordinate is being created with the string from the annotation, but [that method](https://github.com/JetBrains/kotlin/blob/master/libraries/scripting/dependencies/src/kotlin/script/experimental/dependencies/ExternalDependenciesResolver.kt#L44) 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?

---

<div class="post-metadata">

**Author:** ![anthonydahanne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/anthonydahanne/32/5212_2.png) [@anthonydahanne](https://discuss.kotlinlang.org/u/anthonydahanne)\
**Post date:** [October 27, 2020, 7:38pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/7 "2020-10-27T19:38:18Z")

</div>

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

> <https://github.com/Kotlin/kotlin-script-examples/issues/5>
>
> Hello,
> 
> I was not able to find any documentation wrt the \`Repository\` interfac…e.
> 
> My current problem is that I can't find a way to provide credentials to a private Nexus registry
> 
> I have created a topic in \[Kotlin lang Discourse\](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688)
> 
> Once I discover how to provide credentials to \`@Repository\`I'll be able to submit a PR with an example.
> 
> If anybody can help with that, please let me know!

---

<div class="post-metadata">

**Author:** ![anthonydahanne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/anthonydahanne/32/5212_2.png) [@anthonydahanne](https://discuss.kotlinlang.org/u/anthonydahanne)\
**Post date:** [November 11, 2020, 5:22pm UTC](https://discuss.kotlinlang.org/t/kotlin-script-cant-login-to-private-repository/19688/8 "2020-11-11T17:22:10Z")

</div>

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