Specify and switch between ant targets in sublime text 2
Asked Answered
D

3

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.

Difficulty answered 16/8, 2012 at 8:44 Comment(0)
K
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.
Kalbli answered 16/8, 2012 at 15:6 Comment(2)
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.Difficulty
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.Tuition
C
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.

Costanza answered 21/3, 2013 at 16:57 Comment(0)
A
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"
        }
    ]
}
Atween answered 22/1, 2013 at 16:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.