Tiny library to ease the use of environment variables with support for .env files

Overview

Maven License: MIT CI Status

asimov/environment

Tiny library to ease the use of environment variables with support for .env files.

Installation

Gradle (Kotlin)

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.nbottarini:asimov-environment:1.0.1")
}

Gradle (Groovy)

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.nbottarini:asimov-environment:1.0.1'
}

Maven

<dependency>
    <groupId>com.nbottarini</groupId>
    <artifactId>asimov-environment</artifactId>
    <version>1.0.1</version>
</dependency>

Usage

val myEnvValue: String? = Environment["my-env-var"]

val myEnvValue: String? = Environment.get("my-env-var")

val myEnvValue: String = Environment.get("my-env-var", "default value")

val myEnvValue: String = Environment.getOrThrow("my-env-var") // Throws IllegalArgumentException if env var is not present

val allEnvVars = Environment.getAll()

.env

You can create a .env file in the project directory to set environment variables for your development environment.

Sample .env file:

VAR1=VALUE1
VAR2=VALUE2

It is recommended to ignore the .env file from git. You can commit a sample .env.dist file with the default environment variables (without sensitive values like passwords).

The system environment variables takes precedence over .env variables.

By default, the library tries to find the .env file in the working dir and in the parent dirs.

You can specify additional directories to search:

Environment.addSearchPath('./myDir')

Search paths must be configured before accessing any environment variable.

Usage in gradle files

buildscript {
    dependencies {
        classpath("com.nbottarini:asimov-environment:1.0.1")
    }
}

Environment.addSearchPath(rootProject.projectDir.absolutePath)

project.ext {
    set("JDBC_URL", "jdbc:postgresql://${Environment["DB_HOST"]}:${Environment["DB_PORT"]}/${Environment["DB_NAME"]}")
}
You might also like...
A server which delivers the game cache files to an end-user.

RuneTopic Js5 Server A server which delivers the game cache files to an end-user. Setup Guide You can host a js5 server with Docker or with your local

These files are included in an Android Studio Project for a Magic the Gathering Life Counter app. The app was written in Kotlin.
These files are included in an Android Studio Project for a Magic the Gathering Life Counter app. The app was written in Kotlin.

Magic-Life-Counter These files were created in Android Studio using Kotlin. Usage This app was made to keep track of life totals while playing the tra

Kotlin script to prevent invalid conversion errors in projects with many localization files

Localization-Patterns-Checker Kotlin script to prevent invalid conversion errors

Alternative to DreamStorageService, but instead of storing files on a database, it is stored on the file system itself.

EtherealGambi Alternative to DreamStorageService, but instead of storing files on a database, it is stored on the file system itself. I made this beca

A tool to model and analyze the design of systems from .class files
A tool to model and analyze the design of systems from .class files

sift A tool to model and analyze the design of systems from java class files. Features CLI tool for building, querying and diff-ing "system models" fr

🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.
🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

A springboot secure web app with thymeleaf support.

kotlin-web-maven-spring-thyme-challenge-question-aes-encoded-scrypt-encode Description A springboot secure web app with thymeleaf support. Three roles

A springboot secure web app with jsp support.

kotlin-web-maven-spring-jsp-register-rsa-encrypt-argon2-encoded Description A springboot secure web app with jsp support. Three roles are defined; USE

Spring-graphql-getting-started - Spring for GraphQL provides support for Spring applications built on GraphQL Java

Getting Started with GraphQL and Spring Boot Spring for GraphQL provides support

Owner
Nicolas Bottarini
Nicolas Bottarini
A simple GUI frontend for the norns docker environment

This is a simple GUI frontend for the norns docker environment. It displays the virtual norns UI using the screenshot server and exposes OSC controls.

Will Winder 4 Jul 30, 2022
Android SDK development environment Docker image

AndroidSDK Android SDK development environment Docker image Goals It contains the complete Android SDK enviroment, is able to perform all regular Andr

Jing Li 1k Dec 30, 2022
Kotlin scripting environment based on TabooLib

Artifex Artifex 提供了完善的 Kotlin Script (.kts) 运行环境,且支持 TabooLib 全特性。 val compiledScript = Artifex.api().scriptCompiler().compile { // 传入源文件 it.

TABOO-PROJECT 19 Sep 11, 2022
Bukkit library written in Kotlin to make with compatibility and ease non-playable-character (NPC)

mc-npk Easy to use, fast and efficient library to make non-playable-characters (

Luiz Otávio 3 Aug 4, 2022
This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.

Lego 4 Rent This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin. To

Nico Krijnen 4 Jul 28, 2022
Gradle plugin which allows to use typed DSL for generating kubernetes/openshift YAML files

gr8s Gradle plugin which allows using typed DSL for generating kubernetes/openshift YAML files. Based on kuberig Usage import io.github.guai.gr8s.Gene

null 0 Jan 3, 2022
🧶 Library to handling files for persistent storage with Google Cloud Storage and Amazon S3-compatible server, made in Kotlin

?? Remi Library to handling files for persistent storage with Google Cloud Storage and Amazon S3-compatible server, made in Kotlin! Why is this built?

Noelware 8 Dec 17, 2022
This library is created to make files uploading and downloading on Aws easier

S3Manager - aws files uploading library This library is created to make files uploading and downloading on Aws easier Features Easy to use Single/mult

Rajesh Khuti 0 Apr 30, 2022
Easy app for managing your files without ads, respecting your privacy & security

Simple File Manager Can also be used for browsing root files and SD card content. You can easily rename, copy, move, delete and share anything you wis

Simple Mobile Tools 1.2k Dec 29, 2022
The source files to the prototype app for the TomTom n.EXT Hackathon

nEXT-Hackathon2021 The source files to the prototype app for the TomTom n.EXT Hackathon. We are team MoTomized from Codam Coding College attempting to

null 0 Nov 11, 2021