Gradle Vagrant Plugin

This is a Vagrant Plugin for Gradle. It is used internally at Coherent Software Australia, and has been released under the Apache licence (v2) in the hope someone else might find it useful.

Its primary purpose is to assist testing projects by managing a Vagrant virtual machine.

The task types added to your project can be thought of as belonging to one of two groups. The 'basic' types have a one-to-one relationship with vagrant commands. This group includes tasks such as VagrantUp, VagrantDestroy, VagrantSsh. They expect you to micro-manage any dependencies or requirements.

The other group of tasks are more intelligent. They will adjust their interaction with Vagrant according to the current status of the VM.

This plugin will not create or alter a VagrantFile, nor will it init a vagrant directory. All tasks assume the VagrantFile and vagrant project directory have already been correctly configured.


The build system uses the Gradle wrapper. Therefore the only requirement is Java 6 or later.


will build the plugin.


Common to all Vagrant plugin tasks


buildscript {
    dependencies {
        classpath locationOfPluginJar

apply plugin: 'vagrant'

vagrant {
    path = '/usr/bin/vagrant' // the default value
    baseDir = 'vagrant' // the location of the vagrant project, should be valid for use with Gradle's project.file()

The basic tasks

All tasks accept optional machineName(s). If supplied, that task will act only on the named machine(s).


task dbVmUp(type: VagrantUp) {
    machineName 'db'

task allVmsUp(type: VagrantUp)


task cleanVms(type: VagrantDestroy)


task stopVms(type: VagrantHalt)


task provisionVms(type: VagrantProvision)


task resetBackendVms(type: VagrantReload) {
    machineNames ['db','store']


task resumeVms(type: VagrantResume)


task pauseVms(type: VagrantSuspend)


task restartJettyInVmOne(type: VagrantSsh) {
    machineName 'JettyOne'
    command = 'sudo service jetty8 restart'

task compileLegacyProjectWithinVm(type: VagrantSsh) {
    command = 'cd /data/project; make'

The 'intelligent' task


Does the minimum necessary to ensure the vm is running.

task ensureDbAvailable(type: VagrantRunning) {
    machineName 'db'
    alwaysProvision = true
    alwaysReload = false


This software is released under the Apache License, Version 2.0. Please see the copy of the licence, included in this directory as LICENSE, for details.

Bugs, Wishlist

The implemented features could be more generalised: they are currently specific to our use cases.

Documentation could be improved.

There are probably many ways the plugin could be made more robust.

Feel free to fork and send pull requests! Home page on BitBucket at