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
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.
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.
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.