fwcd / fwcd/kotlin-debug-adapter

Any way to support environment variables?

Open
#39 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
150
Forks
29
PR merge metrics
No merged PRs in 30d

Description

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

```kotlin
fun main(args: Array) {

// 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](https://user-images.githubusercontent.com/2606944/85646656-85f6f680-b6d7-11ea-8f85-baf652587142.png)

## Appendix

launch.json

```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

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the supplied kotlin-quick-start example, Main.kt, and launch.json using MESSAGE=test, comparing ./gradlew run with Kotlin Launch. Trace how the adapter handles the launch configuration and determine where environment variables are passed into the debug session. Done means the adapter launch makes System.getenv("MESSAGE") return test, with coverage or documentation for the supported configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.