Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify and switch between ant targets in sublime text 2

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.

like image 272
tomraithel Avatar asked Aug 16 '12 08:08

tomraithel


3 Answers

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 the variants array will run on ctrl+shift+b
  • Any cmd in the variants array can be run via the command palette by searching for name. i.e. hit ctrl+shift+p and type Solve World Hunger to run the solve world hunger command.
like image 139
Matt York Avatar answered Sep 23 '22 10:09

Matt York


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.

like image 45
Matt Balkam Avatar answered Sep 25 '22 10:09

Matt Balkam


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"
        }
    ]
}
like image 40
user1806692 Avatar answered Sep 23 '22 10:09

user1806692