# Kotlin DSL in gradle - how do I use Base64

**URL:** <https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904>\
**Category:** Support\
**Created:** [September 8, 2021, 4:10pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904 "2021-09-08T16:10:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phill/32/8551_2.png) [@phill](https://discuss.kotlinlang.org/u/phill)\
**Post date:** [September 8, 2021, 4:10pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904/1 "2021-09-08T16:10:13Z")

</div>

HI there, I am using kotlin dsl in my gradle build scripts by preference. I recently needed to do a Base64 encode… but its failed to resolve Base64.Encoder even though it resolved Base64:

Reproduce with a gradle init, choose library, kotlin, kotlin. Add the following to lib:build.gradle.kts

```auto
import java.util.*

...............................

fun getBase64EncodedCredentials(): String {
    // This works in a gradle.build file
    // return "the quality of mercy is not strained".bytes.encodeBase64().toString()
    val bytes = "it dropeth as the gentle rain fro heaven to that place beneath".toByteArray()
    val encoder = Base64.getEncoder()
    return encoder.encode(bytes)
}

```

In the .kts file I get wiggly red underlines on the references to the encoder.

Am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [September 8, 2021, 4:55pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904/2 "2021-09-08T16:55:01Z")

</div>

Are you sure there is a problem with resolving `Base64.Encoder`? Because you have a different bug in this code: `encode()` returns `ByteArray`, but you declared your function to return `String`.

---

<div class="post-metadata">

**Author:** ![phill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phill/32/8551_2.png) [@phill](https://discuss.kotlinlang.org/u/phill)\
**Post date:** [September 8, 2021, 5:49pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904/3 "2021-09-08T17:49:10Z")

</div>

You are right - the return type does not match. I corrected that, but the compiler still fails to resolve Base64.Encoder:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/c/c4400fa8c4fa8316450c0913dab04771bd9e6ce7.png)

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [September 8, 2021, 5:58pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904/4 "2021-09-08T17:58:25Z")

</div>

FYI, I followed your instructions and it works without problems (Java 14). Does this problem occur when using gradle from the command line?

---

<div class="post-metadata">

**Author:** ![phill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phill/32/8551_2.png) [@phill](https://discuss.kotlinlang.org/u/phill)\
**Post date:** [September 8, 2021, 6:33pm UTC](https://discuss.kotlinlang.org/t/kotlin-dsl-in-gradle-how-do-i-use-base64/22904/5 "2021-09-08T18:33:50Z")

</div>

Doh! I usually remember to try that. Good shout - it seems to be associated with the ide (intellij). But the warning does not stop the build from running - either on the command line or in the ide.

Thanks

Phill
