7

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.

3 Answers 3

11

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.
2
  • 1
    Matt, thank very much for that snippet! It works awesome. One thing to mention here though: ctrl+shift+b does not run the last cmd in the variants array, it searches for the variant with the name Run and executes that one. Figured that out by taking a look at the default key bindings.
    – tomraithel
    Aug 17, 2012 at 9:25
  • 1
    Would you care to expand on the 'save this build file'? It seems to me that the only way I can get this to work, is if I save the file as a *.sublime-build file in the Packages/User folder.
    – andkrup
    Jan 5, 2013 at 17:39
3

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.

2

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"
        }
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.