'kotlin dotenv doesn't take directory configuration

Trying to use kotlin-dotnet, but this is not working, using kotlin object class, to manage singleton

Got error Could not find /asset/env on the classpath whereas the env file is in /assets folder as mentionned in the doc

object EnvVariables {
    val envVar: Dotenv =
        dotenv {
            directory = "/assets"
            filename = "env"
    }
}

object RetrofitInstance {

    val api: TodoService by lazy {
        Retrofit.Builder()
            .baseUrl(EnvVariables.envVar["BASE_URL"])
            .addConverterFactory(GsonConverterFactory.create())
            .build()
            .create(TodoService::class.java)

    }
}

env in assets folder

Error



Solution 1:[1]

Most likely the doc is not accurate

In file DotEnvReader.java

return ClasspathHelper
            .loadFileFromClasspath(location.replaceFirst("./", "/"))
            .collect(Collectors.toList());

So, you can fix it by adding "."

var dotenv = dotenv {
    directory = "./assets" //use ./ instead of /
    filename = "env"
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 y-io