This message was deleted.
# community-support
s
This message was deleted.
v
Doesn't sound so much like a Gradle question, does it? What is
.env
or
DotEnv
and how is it related to Gradle?
j
Okay I'll try to write it differently, let's say I have some API_KEY variable that needs to be saved during compile so that I can use it in the runtime .jar file.
v
Write it to some file, for example by having a properties file with a placeholder and then configure the
processResources
task using
expand
to replace the placeholder.
j
and won't the final KEY be seen in the unwrapped .jar?
v
Of course it will be in the jar, that's what you asked for
j
Yes, I understand that, but my point is that no one can abuse the API_KEY. it's an opensource library I'm making.
v
If you don't want it in the jar, read it from an environment variable or from a system property or from a file that you for example configure through an environmant variable or system property, ...
j
I'm sorry but I'm pretty new to gradle, and I'm not talking about java at all, could you give me a small example?
so far I've got something like this
Copy code
processResources {
    def props = [version: version]
    inputs.properties props
    filteringCharset 'UTF-8'
    filesMatching('plugin.yml') {
        expand props
    }
}

task api() {
    Properties properties = new Properties()
    def propertiesFile = project.rootProject.file('local.properties')
    if (propertiesFile.exists()) {
        properties.load(propertiesFile.newDataInputStream())
    }
    ext.apiToken = properties.getProperty('api.token');
}
v
Besides that you do quite some really bad things in that short snippet, your question is still unclear. You say you are not talking about Java but about Gradle. But you say you need that value at runtime. But you don't want the value in the jar. And you don't want to read it from the Java code. ....?
j
You know if I say it stupidly I am a PHP, JS developer where it was enough to just write the variables in the .env file then use an external library that could read it and done. My problem is that I'm trying to somehow store a variable with a github api key when compiling. However, I don't want it to be read from a
.jar
file I don't know if something like that is even possible in java/gradle.
that should be okey?
Copy code
processResources {
    Properties properties = new Properties()
    def propertiesFile = project.rootProject.file('local.properties')
    properties.load(propertiesFile.newDataInputStream());
    def props = [version: version, api_key: properties.get("api.token")]
    inputs.properties props
    filteringCharset 'UTF-8'
    filesMatching('plugin.yml') {
        expand props
    }
}
v
Well, that is what I said above. And with that it will write the api key into the
plugin.yml
and that file will be present in the jar, so it will be discoverable from the jar. That's why I then said if you don't want it discoverable from the jar, you need to read it for example from an environment variable or system property or file and configure that accordingly in the runtime environment.
j
1. yeah i did basically like that, tbh i just replace some things inside the key and then use a byteCode.