Specify and switch between ant targets in sublime text 2
-
26-06-2021 - |
Domanda
I´m using Sublime Text 2 together with the ant build system. CTRL+B works perfectly fine to start the build with the default target. However my question is, is there a ways to define different ant build targets and have a mechanism to switch between them easily?
I thought about creating additional custom build commands for each target - for example like "clean". It works, but that is not the best approach in my eyes because you have to go to "Tools > Build System > Ant (clean)" and hit CTRL+B afterwards.
Soluzione
Save this build file as *.sublime-build file in the Packages/User folder
{
"selector": "source.java",
"cmd": ["ant"],
"variants": [
{ "cmd": ["solve_world_hunger"],
"name": "Solve World Hunger"
},
{ "cmd": ["ant", "clean"],
"name": "Run"
}
]
}
- Default target will build on
ctrl+b
- The cmd named
Run
in thevariants
array will run onctrl+shift+b
- Any cmd in the variants array can be run via the command palette by searching for
name
. i.e. hitctrl+shift+p
and typeSolve World Hunger
to run the solve world hunger command.
Altri suggerimenti
You can declare variants as shown in the other solutions. I also like to add in this to my user keybindings:
{
"keys": ["ctrl+b"],
"command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Build:"}
},
With this, you can hit ctrl+b then after that, either enter for the default build, or start typing the variant type. c for clean r for release, whatever.
This is what I had to do to get mine to work on windows 7, like the answer above save it in your Packages/User folder and then you can trigger different build targets by pressing ctrl+shift+p and typing the name of the command within the variants section of the script below.
Hope this helps some people :)
{
"working_dir": "${project_path:${folder}}",
"selector": "source.java",
// DEFAULT COMMAND TO EXECUTE FOR A BUILD SCRIPT ** OPTIONAL **
//"cmd": ["ant.bat", "deploy_test"],
"variants":
[
{ "cmd": ["ant.bat", "deploy_test"],
"name": "Laravel Deploy Dev"
},
{ "cmd": ["ant.bat", "deploy_delete"],
"name": "Laravel Delete"
}
]
}