Gradle Vagrant plugin

Gradle plugin for managing Vagrant boxes.

License

License

Categories

Categories

Gradle Build Tools Ant Vagrant Container Virtualization Tools
GroupId

GroupId

com.bmuschko
ArtifactId

ArtifactId

gradle-vagrant-plugin
Last Version

Last Version

3.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Gradle Vagrant plugin
Gradle plugin for managing Vagrant boxes.
Project URL

Project URL

https://github.com/bmuschko/gradle-vagrant-plugin
Source Code Management

Source Code Management

https://github.com/bmuschko/gradle-vagrant-plugin

Download gradle-vagrant-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/com.bmuschko/gradle-vagrant-plugin/ -->
<dependency>
    <groupId>com.bmuschko</groupId>
    <artifactId>gradle-vagrant-plugin</artifactId>
    <version>3.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.bmuschko/gradle-vagrant-plugin/
implementation 'com.bmuschko:gradle-vagrant-plugin:3.0.0'
// https://jarcasting.com/artifacts/com.bmuschko/gradle-vagrant-plugin/
implementation ("com.bmuschko:gradle-vagrant-plugin:3.0.0")
'com.bmuschko:gradle-vagrant-plugin:jar:3.0.0'
<dependency org="com.bmuschko" name="gradle-vagrant-plugin" rev="3.0.0">
  <artifact name="gradle-vagrant-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.bmuschko', module='gradle-vagrant-plugin', version='3.0.0')
)
libraryDependencies += "com.bmuschko" % "gradle-vagrant-plugin" % "3.0.0"
[com.bmuschko/gradle-vagrant-plugin "3.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Gradle Vagrant plugin Build Status

Vagrant Logo

Gradle plugin for managing Vagrant boxes.

Usage

To use the plugin, include in your build script:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-vagrant-plugin:3.0.0'
    }
}

Base plugin

If you want to create your own task for managing Vagrant, you should go with the base plugin. This option is usually helpful if you are dealing with multiple VMs in parallel. The base plugin provides all custom task types and preconfigures them with sensible defaults. To use the base plugin, add the following apply notation to your build script.

apply plugin: 'com.bmuschko.vagrant-base'

Custom task types

The base plugin provides the following custom task types:

Type Description

VagrantDestroy

Stops the running machine Vagrant is managing and destroys all resources.

VagrantHalt

Shuts down the running machine Vagrant is managing.

VagrantReload

The equivalent of running a halt followed by an up.

VagrantSsh

Executes a SSH command on the Vagrant machine.

VagrantSshConfig

Outputs the valid configuration for an SSH config file to SSH.

VagrantStatus

Outputs the state of the machines Vagrant is managing.

VagrantSuspend

Suspends the guest machine Vagrant is managing.

VagrantUp

Creates and configures guest machines according to your Vagrantfile.

Extension properties

The base plugin defines the following extension properties in the vagrant closure:

Property name Type Default value Description

boxDir

File

project.file("vagrant")

The directory the targeted Vagrant box resides in.

provider

String

virtualbox

The backend provider to be used.

The recommended way for providing values to the Vagrantfile from the outside is to use environment variables. This is made possible through the nested configuration element environmentVariables. This element exposes the method variable that takes two parameters: the key and value for a environment variable. For each invocation of this method a new key/value pair is added to internal property named variables.

Property name Type Default value Description

variables

Map<String, String>

[:]

Provided environment variables as key/value pairs.

By default the plugin validates the installation of the Vagrant runtime and the selected provider. This validation logic can be disabled from your buildscript. This is made possible through the nested configuration element installation. This element exposes the method validate that take a single parameter.

Property name Type Default value Description

validate

Boolean

true

Installation validation

Example

import com.bmuschko.gradle.vagrant.tasks.VagrantUp
import com.bmuschko.gradle.vagrant.tasks.VagrantDestroy

ext {
    virtualBoxDir = file('virtualbox-box')
    fusionBoxDir = file('fusion-box')
    fusionProvider = 'vmware_fusion'
}

task startVirtualBoxVm(type: VagrantUp) {
    description = 'Starts VM machine running on VirtualBox.'
    group = 'VirtualBox VM'
    boxDir = virtualBoxDir
}

task stopVirtualBoxVm(type: VagrantDestroy) {
    description = 'Stops VM machine running on VirtualBox.'
    group = 'VirtualBox VM'
    boxDir = virtualBoxDir
}

task startFusionVm(type: VagrantUp) {
    description = 'Starts VM machine running on VMware Fusion.'
    group = 'Fusion VM'
    boxDir = fusionBoxDir
    provider = fusionProvider
}

task stopFusionVm(type: VagrantDestroy) {
    description = 'Stops VM machine running on VMware Fusion.'
    group = 'Fusion VM'
    boxDir = fusionBoxDir
    provider = fusionProvider
}

Convention plugin

If you want the plugin to preconfigure commonly-used tasks for you, you should go with the full-fledged convention plugin. This plugin is a viable option if you only have to deal with a single VM. To use the convention plugin, add the following apply notation to your build script.

apply plugin: 'com.bmuschko.vagrant'

Default tasks

The plugin defines the following tasks:

Task name Depends on Type

vagrantDestroy

-

VagrantDestroy

vagrantHalt

-

VagrantHalt

vagrantReload

-

VagrantReload

vagrantResume

-

VagrantResume

vagrantSshConfig

-

VagrantSshConfig

vagrantStatus

-

VagrantStatus

vagrantSuspend

-

VagrantSuspend

vagrantUp

-

VagrantUp

Example

vagrant {
    boxDir = file('~/dev/my-vagrant-box')

    environmentVariables {
        variable 'IP', '192.168.1.33'
        variable 'OPERATINGSYSTEM', 'redhat'
    }

    installation {
        validate = false
    }
}

import com.bmuschko.gradle.vagrant.tasks.Vagrant
import com.bmuschko.gradle.vagrant.tasks.VagrantSsh

task vagrantListsBoxes(type: Vagrant) {
    description = 'Outputs a list of available Vagrant boxes.'
    commands = ['box', 'list']
}

task vagrantEcho(type: VagrantSsh) {
    description = 'Runs remote SSH command in Vagrant box.'
    sshCommand = "echo 'hello'"

    dependsOn vagrantUp
    finalizedBy vagrantDestroy
}

Versions

Version
3.0.0
2.2.1
2.2