问题
I have a huge project spread across multiple source directories which was developed the last 15 years using eclipse with custom external tools configurations to launch ant tasks from build.xml files anywhere inside the source directories (a big mess, I know!).
As the everyday work is mostly xml and JavaScript based, I thought of VSCode as a lightweight alternative (as eclipse is e.g. unable to deal with large xml files without exceeding HeepSpace). Task Runners look to me like a great way to integrate the ant builds into the editor, they are also advertised as capable of running ant builds:
Examples are Make, Ant, Gulp, Jake, Rake and MSBuild to name only a few.
I am able to run ant builds with the build.xml in the root folder. This is however not how the project is structured.
Is there a way to run the task command (ant, in my case) from a directory different to the workspace root?
I think of something like git's GIT_WORK_TREE
environment variable or a way to perform two commands (like cd {{build.xml folder}} && ant
). My current tasks.json is
{
"version": "0.1.0",
"command": "ant",
"isShellCommand": true,
"showOutput": "silent",
"args": ["all", "jar"],
"promlemMatcher": "" // I'm also not sure what to put here,
// but that's another question
}
(I'm on windows, btw -- but come from linux/osx and am kinda new to the ways thinks work here.)
回答1:
You can either define the cwd directory to be used. This is done like this:
{
"version": "0.1.0",
"command": "ant",
"isShellCommand": true,
"options": {
"cwd": "My folder to run in"
}
}
See https://code.visualstudio.com/Docs/editor/tasks_appendix for a definition of the tasks.json
file.
来源:https://stackoverflow.com/questions/31958496/vscode-task-to-run-ant-buildfile-located-anywhere