I want to configure a tasks.json
file in VS Code to run python and java code just pressing:
Ctrl + Shift + B
Python and Java are configured but it needs two different tasks.json
files.
But I can just keep one tasks.json
file in the .vscode
folder.
How can I merge two config file in a tasks.json file ?
For Python:
{
"version": "2.0.0",
"tasks": [{
"label": "Compile and run",
"type": "shell",
"command": "",
"args": [
"/usr/bin/time",
"-v",
"--output",
"sys.txt",
"timeout",
"5",
"python3",
"${relativeFile}",
"<",
"input.txt",
">",
"output.txt",
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "py",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}],
}
For Java :
{
"version": "2.0.0",
"tasks": [{
"label": "Compile and run",
"type": "shell",
"command": "",
"args": [
"/usr/bin/time",
"-v",
"--output",
"sys.txt",
"timeout",
"5",
"java",
"${relativeFile}",
"<",
"input.txt",
">",
"output.txt",
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "java",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}],
}
If you have the java or python file open (and the two tasks "merged" as @tHeSID suggested), you can just overload the keybindings ala:
{
"key": "ctrl+shift+B",
"command": "workbench.action.tasks.runTask",
"args": "Compile and run Python",
"when": "editorLangId == python"
},
{
"key": "ctrl+shift+B",
"command": "workbench.action.tasks.runTask",
"args": "Compile and run Java",
"when": "editorLangId == java"
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With