Skip to content

Commit

Permalink
V6 (#50)
Browse files Browse the repository at this point in the history
* upgrade dotenv-java

* upgrade to v 1.1.0 dotenv-java

* coveralls integration

* update readme

* update readme

* add simple maven example

* v6.1

* 6.1.1
  • Loading branch information
cdimascio authored Sep 25, 2020
1 parent d01d17a commit 201010c
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🗝️ dotenv-kotlin

![](https://travis-ci.org/cdimascio/dotenv-kotlin.svg?branch=master) [![Maven Central](https://img.shields.io/maven-central/v/io.github.cdimascio/dotenv-kotlin.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.cdimascio%22%20AND%20a:%22dotenv-kotlin%22) [![Download](https://api.bintray.com/packages/cdimascio/maven/dotenv-kotlin/images/download.svg) ](https://bintray.com/cdimascio/maven/dotenv-kotlin/_latestVersion) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/dotenv-kotlin/badge.svg?branch=master)](https://coveralls.io/github/cdimascio/dotenv-kotlin?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/66b8195f0da544f1ad9ed1352c0ea66f)](https://app.codacy.com/app/cdimascio/dotenv-kotlin?utm_source=github.com&utm_medium=referral&utm_content=cdimascio/dotenv-kotlin&utm_campaign=Badge_Grade_Dashboard) [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors) [![](https://img.shields.io/gitter/room/cdimascio-oss/community?color=%23eb205a)](https://gitter.im/cdimascio-oss/community) ![](https://img.shields.io/badge/license-Apache%202.0-orange.svg)
![](https://travis-ci.org/cdimascio/java-dotenv.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/java-dotenv/badge.svg?branch=v6)](https://coveralls.io/github/cdimascio/java-dotenv?branch=v6) [![Maven Central](https://img.shields.io/maven-central/v/io.github.cdimascio/java-dotenv.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.cdimascio%22%20AND%20a:%22java-dotenv%22) [ ![Download](https://api.bintray.com/packages/cdimascio/maven/java-dotenv/images/download.svg) ](https://bintray.com/cdimascio/maven/java-dotenv/_latestVersion) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/66b8195f0da544f1ad9ed1352c0ea66f)](https://app.codacy.com/app/cdimascio/java-dotenv?utm_source=github.com&utm_medium=referral&utm_content=cdimascio/java-dotenv&utm_campaign=Badge_Grade_Dashboard) [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors) [![](https://img.shields.io/gitter/room/cdimascio-oss/community?color=%23eb205a)](https://gitter.im/cdimascio-oss/community) ![](https://img.shields.io/badge/license-Apache%202.0-orange.svg)

A port of the Ruby dotenv project for Java and Kotlin. Load environment variables from a `.env` file.

Expand Down Expand Up @@ -32,7 +32,7 @@ Looking for the pure Java variant (no Kotlin), get [dotenv-java](https://github.
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-kotlin</artifactId>
<version>6.1.0</version>
<version>6.1.1</version>
</dependency>
```

Expand All @@ -41,7 +41,7 @@ Looking for the pure Java variant (no Kotlin), get [dotenv-java](https://github.
### Gradle

```groovy
compile 'io.github.cdimascio:dotenv-kotlin:6.1.0'
compile 'io.github.cdimascio:dotenv-kotlin:6.1.1'
```

## Usage
Expand Down Expand Up @@ -268,7 +268,7 @@ for (e in dotenv.entries()) {
```

## Examples
- with [Maven (simple)](https:/cdimascio/java-dotenv-example)
- with [Maven (simple)](https:/cdimascio/dotenv-kotlin-example)
- with [Spring MVC](https:/cdimascio/kotlin-spring-mvc-template)
- with [Spring Webflux](https:/cdimascio/kotlin-swagger-spring-functional-template)
- with [Android](https:/cdimascio/android-example/blob/master/app/src/main/java/com/example/dimascio/myapp/MainActivity.kt)
Expand Down
27 changes: 27 additions & 0 deletions examples/maven-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# maven-simple

Simple `dotenv-kotlin` example using maven.

## Clone

```shell
git clone
```

## Compile

```shell
mvn compile
```

## Run

```shell
mvn exec:java -Dexec.mainClass="io.github.cdimascio.examples.dotenv.Main"
```

The program outputs the value of the env var `MY_ENV`. In this case, `MY_VALUE`

## License

MIT
89 changes: 89 additions & 0 deletions examples/maven-simple/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cdimascio.github.io</groupId>
<artifactId>dotenv-kotlin-example</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<kotlin.version>1.4.10</kotlin.version>
</properties>

<dependencies>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-kotlin</artifactId>
<version>6.0.0</version>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>

</dependencies>
<build>
<!-- setup kotlin sources dir -->
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

<plugins>

<!-- compile kotlin -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>

<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>

<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- package app -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
io.github.cdimascio.examples.dotenv.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.cdimascio.examples.dotenv

import io.github.cdimascio.dotenv.Dotenv

object Main {
@JvmStatic
fun main(args: Array<String>) {
val dotenv = Dotenv.configure().load()

// Iterate over each environment entry
// Note: entries in the host environment override entries in .env
dotenv.entries().forEach { println(it) }

// Retrieve the value of the MY_ENV environment variable
println("MY_ENV: " + dotenv["MY_ENV"])

// Retrieve the value of the MY_ENV2 environment variable or return a default value
println("MY_ENV2: " + dotenv["MY_ENV2", "Default Value"])
}
}
1 change: 1 addition & 0 deletions examples/maven-simple/src/resources/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MY_ENV="MY_VALUE"
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-kotlin</artifactId>
<version>6.0.0</version>
<version>6.1.1</version>

<licenses>
<license>
Expand Down Expand Up @@ -50,7 +50,7 @@


<properties>
<dotenv.version>1.1.0</dotenv.version>
<dotenv.version>2.0.0</dotenv.version>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tests/JavaTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void iteratorOverDotenvWithFilter() {
.ignoreIfMalformed()
.load();

Set<DotenvEntry> entriesInFile = dotenv.entries(DotenvEntry.Filter.DECLARED_IN_ENV_FILE);
Set<DotenvEntry> entriesInFile = dotenv.entries(Dotenv.Filter.DECLARED_IN_ENV_FILE);
Set<DotenvEntry> entriesAll = dotenv.entries();
assertTrue(entriesInFile.size() < entriesAll.size());

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/tests/DslTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class DotEnvDslTest {
.ignoreIfMalformed()
.load()

val entriesInFile = dotenv.entries(DotenvEntry.Filter.DECLARED_IN_ENV_FILE)
val entriesInFile = dotenv.entries(Dotenv.Filter.DECLARED_IN_ENV_FILE)
val entriesAll = dotenv.entries()
assertTrue(entriesInFile.size < entriesAll.size)

Expand Down

0 comments on commit 201010c

Please sign in to comment.