Giter Club home page Giter Club logo

Comments (5)

cdimascio avatar cdimascio commented on May 24, 2024

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

jayceekay avatar jayceekay commented on May 24, 2024

thanks for the quick response. I'll check it out tomorrow

from dotenv-kotlin.

jayceekay avatar jayceekay commented on May 24, 2024

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.

cdimascio avatar cdimascio commented on May 24, 2024

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.

PericlesTheo avatar PericlesTheo commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.