Skip to content

Any way to support environment variables? #39

Open
@thunderz99

Description

@thunderz99

Problem

Seems there is no way to pass environment variables to the kotlin-debug-adapter.
I need to pass database connection strings by environment variables in my project.

I'll be appreciated if any way provided to do this.
(If any hint to implement this, I'll try to add a pullrequest.)

To reproduce

Clone the kotlin-quick-start repo. Add the following line to Main.kt.

fun main(args: Array<String>) {

        // added to test environment variables
	println("""System.getenv("MESSAGE"): ${System.getenv("MESSAGE")} """)
	println("Hello world")
}

Use ./gradlew run you can get the environment variables(MESSAGE=test)

% export MESSAGE="test" && ./gradlew run

> Task :run
System.getenv("MESSAGE"): test 
Hello world

BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed

Use Kotlin Launch, I cannot get the environment variables.

[INFO] main      Connected to client
[INFO] async1    Resolving dependencies for 'kotlin-quick-start' through Gradle's CLI...
[INFO] async1    Creating temporary gradle file /var/folders/51/7dvp_d0969z9v2y05l6knplc0000gn/T/classpath14115259569083174887.gradle
[INFO] async1    Successfully resolved dependencies using Gradle dependencies CLI
[INFO] async1    Starting JVM debug session with main class MainKt
System.getenv("MESSAGE"): null 
Hello world
[INFO] eventBus  Sent exit event
[INFO] async0    Exiting JDI session

I tried to add a "env" property to launch.json but there is no luck.
image

Appendix

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "kotlin",
            "request": "launch",
            "name": "Kotlin Launch",
            "projectRoot": "${workspaceFolder}",
            "mainClass": "MainKt",
            "preLaunchTask": "build"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "./gradlew build -x test",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

The kotlin-quick-start repo that reproduces.
https://github.com/thunderz99/kotlin-quick-start/tree/topics/test-environment-variables

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions