Can I load a .env file for a module instead of the whole project?
There are some utils for loading .env files, can this support the above?
Or do I need to use my own solution here.
Solution:Jump to solution
I see what you mean, I'll change the working directory in the IDEA run configuration
46 Replies
What's your use-case specifically?
.env
is a standard and is parsed at runtime, so I'm curious what you're trying to do hereMy bot is in a module, not the root project, the .env in my module isn't being loaded
the
.env
must be located in your current working directory
otherwise, yeah, it won't find it
dotenv is a sort of informal standard - it's a key-value file, it supports line comments, and it must be placed in the current working directory
(it's not a kordex thing, we just provide a util for it)I have seen implementations in the past where multiple .env files are supported for sub projects, with descending priority etc
No worries - I'll have to implement something else then
I'm not really sure of the context you're working with
it doesn't make sense to me to ask for a .env for a subproject because that implies you're resolving it at compile-time
whereas .env is intended for users to fill out for run-time configuration
It's being used as a dev runtime configuration
is there a reason you can't put it in your cwd?
I guess I could make the util check the classpath
that doesn't seem very useful, though
Solution
I see what you mean, I'll change the working directory in the IDEA run configuration
yeah I mean for dev you'd probably just put it in your project root and gitignore it
There are multiple modules which have separate .env files
I see
This works now,thanks
no worries, but if you can think of an approach that might help out better, I'm happy to look into it
This is an implementation I saw on some typescript framework a while back, it seemed nice and intuitive for me.
if I run moduleA,
.env
from root
and .env
from moduleA
are loaded, overwriting the root environment.so
moduleA
is executable as well?It can be sure, depends on your project
the question then is how KordEx would figure out how to traverse the tree
I guess the gradle plugin would make it possible
since it could supply a system property or.. something
I'm overlooking some details here
Related to running code in a jar, vs from the IDE
I don't think it needs a plugin, can just look at the directory structure when running in IDE
well, I don't think this approach makes sense for production
No but is .env meant for production?
yes
Okay fair enough
I wonder if I could just make the kordex gradle plugin configure the application plugin
then it'd parse the .envs there and insert them into the runtime env vars that way
are you using the kordex gradle plugin?
I'd personally have curent module > working directory > project root, the former and latter are optional
I don't think so
mkay
I don't think this is something kordex could realistically do on its own
because it has to figure out how far up to look for .env files
but with gradle's help it should work
Yeah well if I get some spare time maybe I'll put a pull request in, I'm better at explaining things using code lol
it's okay, I get what you're saying haha
I'll open an issue on the gradle plugins repo so I don't forget
Okay sounds good thank you
will link in a few
Just an aside, my kordex bot is in 133 servers now 😮
Nice, good work \o/
are you using kordex v2? just out of curiosity
val kordexVersion = "1.9.0-SNAPSHOT"
ah okay, you're on v1 still
that's all good, v2 is like, a couple days old
lmao
stable?
as stable as v1
I haven't had any reports yet
anyway let me get this issue typed up
https://github.com/Kord-Extensions/gradle-plugins/issues/5
I think that's correct, right?
Is this suggesting to bundle the .env files with the app?
No
the application plugin provides a
run
task
you'd use that to run your development bot
the kordex plugin already configures it, but only with the main classOkay, if its part of the run task then yes that sounds good to me
okay, cool
alright then, I'll work on that when I get the chance
probably this weekend
you can watch the issue, I'll update it when it happens
Okay great thanks 🙂
o7
you will need to move to the gradle plugin for it though
but that's all documented if you need it https://docs.kordex.dev/kordex-plugin.html
Kord Extensions Help
KordEx Plugin | Kord Extensions
you can do that now, but bear in mind that it will default to kordex v2 if you don't specify a version, and v2 has a different package layout
(among other changes)
I detailed the changes here if needed https://docs.kordex.dev/about.html#version-2
overriding works too
okay cool this works
I'm not ready to ship yet but I figured I'd post an update
OK, shipping
See https://discord.com/channels/1121419906995458098/1121524367818498128/1273968152945889343 :>