Comments (5)
@jayceekay The following repo contains a spring-mvc project. It uses kotlin, instead of java. I hope it provides for a helpful example.
You can find the repo here
https://github.com/cdimascio/kotlin-spring-mvc-template
Note for this project, the dotenv instance is made available globally (with java it could be public static final)
Files of note...
Build.gradle
https://github.com/cdimascio/kotlin-spring-mvc-template/blob/master/build.gradle
Dotenv instance inits here
https://github.com/cdimascio/kotlin-spring-mvc-template/blob/master/src/main/kotlin/api/Application.kt
Hope this helps
from dotenv-kotlin.
thanks for the quick response. I'll check it out tomorrow
from dotenv-kotlin.
this seems to work when loading the spring app, but since this configuration is happening when the spring app runs would this take effect for other gradle tasks? for example when i run the spring app i can clearly see it's ingesting my .env
file, but when i run ./gradlew flywayInfo
i see this:
$ ./gradlew flywayInfo
> Task :flywayInfo FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':flywayInfo'.
> Error occurred while executing flywayInfo
Unable to connect to the database. Configure the url, user and password!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more
log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
1 actionable task: 1 executed
edit: just to clarify, that's why i was hoping to inject it into the build.gradle
itself, to make dotenv do its thing and create an ENV which is accessible to all the gradle tasks
from dotenv-kotlin.
What you want to do is certainly doable, however I'm not a gradle expert.
Nonetheless, perhaps this SO post will help some or at least help you to put you on the right path.
https://stackoverflow.com/q/26314709/2616755
Note that in your case, you need to load the lib from maven Central, rather than use a local jar. You'll likely need to be sure mavencentral repo is available for the buildscript
from dotenv-kotlin.
I don't know if this is relevant for others but this is how I solved this in my build.gradle.tks
import io.github.cdimascio.dotenv.dotenv
val dotenv = dotenv {
ignoreIfMissing = true
}
// The buildscript was the thing I needed
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("io.github.cdimascio:dotenv-kotlin:6.4.1")
}
}
dependencies {
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
}
With this change, I was able to do read the env vars in build.gradle.tks
repositories {
mavenCentral()
maven(dotenv.get("SOME_MAVEN_URL")) // Random example but now the .env is read
}
from dotenv-kotlin.
Related Issues (20)
- Dotenv entries() result is not overridden by environment variables HOT 3
- Not working correctly when I execute a jar after gradle build HOT 2
- Option to only load .env file env vars HOT 6
- Multiline value HOT 8
- using env vars from host, it requires .env file HOT 1
- Directory configuration not working correctly HOT 3
- 5.1.3 library version does not resolve correctly .env file location in jar file. HOT 3
- How is it different from Spring properties? HOT 5
- Make dotenv env variables available in System.getProperty() too HOT 6
- .env file and Travis HOT 5
- Getting an error when running a jar that uses dotenv HOT 1
- kotlin libs are required HOT 3
- Update version in readme
- Crashes on Android version 7 and older HOT 2
- package version 6.3.0 is not published anywhere other than github packages HOT 1
- Android Could not find /asset/env on the classpath HOT 1
- Errors when attempting to start it from a jar.
- Latest build on maven HOT 1
- Feature missing in docs.. DECLARED_IN_ENV filter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotenv-kotlin.