【发布时间】:2026-01-20 12:45:01
【问题描述】:
我想在 VS Code 中配置一个tasks.json 文件来运行 python 和 java 代码只需按下:
Ctrl + Shift + B
Python 和 Java 已配置,但需要两个不同的 tasks.json 文件。
但我只能在.vscode 文件夹中保留一个tasks.json 文件。
如何将两个配置文件合并到一个 tasks.json 文件中?
对于 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
}
}
}],
}
对于 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
}
}
}],
}
【问题讨论】:
标签: json visual-studio-code vscode-settings vscode-tasks