Like many software projects, frameworks, plugins they start off because the author could not find a solution that really fitted their needs and submitting pull requests to existing projects would not have changed the direction of such projects to the needs of the author. This is one of those kind of projects and it is offered against a number of alternative solutions that are available as Gradle plugins.

The aim with the group of plugins is making the integration of Packer into the build automation pipeline as smooth as possible. This brought with it a number of subgoals:

  • Simplicity to use defaults - convention over configuration

  • Maximum flexibility if you need it.

  • No need to install packer or relevant tools - let Gradle take care of it for you.

This is an incubating project. Until is 1.0 released one day, interfaces and DSL may change between 0.x releases.

Alternative solutions

This is not the only solution. You might also want to look at


These plugins are available from the plugin portal. Add the appropriate plugin identifiers to your build.gradle file depending on the type of functionality you require.

plugins {
  id 'org.ysb33r.packer.base'  version '0.1.2'  // <1>
  id 'org.ysb33r.packer'       version '0.1.2'  // <2>
1 Base plugin
2 Conventions for packer
You need at least Gradle 2.8 to use these plugins.

Base plugin

The base plugin provides:

Packer plugin

The Packer plugin provides:

Applying the Packer plugin will apply the base plugin.

Platform installation support

These plugins can automatically download, cache and render Node for the following platforms:

  • Linux 32 & 64-bit.

  • Mac 64-bit.

  • Windows 32 & 64-bit.

  • FreeBSD 32 & 64-bit.

Should you need to run Gradle on a platform not listed above, but which Node supports and on which Gradle can run, you will need to configure the Node executable via the path or search methods. You can also raise an issue to ask for the support or you can submit a PR with the solution.

Packer Extension

The packer project extension configures a method of obtaining a packer executable. On supported platforms it offers the option of configuring a Packer version, which Gradle will then download, cache and use.

packer {
    executable version : '1.0.3' (1)

packer {
    executable path : '/path/to/packer' (2)

packer {
    executable searchPath() (3)
1 Set a version. On supported platforms Gradle will download, cache and use this version.
2 Specify a hard-coded path where to find the packer executable.
3 Tell Gradle to search the system path for the packer executable.

The PackerBuilder task type

The base plugin (org.ysb33r.packer.base) makes a PackerBuilder task type available. If the the Packer plugin (org.ysb33r.packer) is applied it will create a task of this type called packerBuild.

packerBuild {
    includes = [ 'box1' ]   (1)
    includes 'box2', 'box3' (2)
    excludes = [ 'box4' ]   (3)
    excludes 'box5', 'box6' (4)

    force true              (5)
    parallel false          (6)

    template  '/path/to/spec.json' (7)
    outputDir "${buildDir}/work"   (8)

    vars aws_access_key : 'MY_ACCESS_KEY',
        aws_secret_key : { 'MY SECRET KEY' } (9)
1 Replace current set of images to include with a new set.
2 Add to current set of included images.
3 Replace current set of images excludes with a new set.
4 Add more images to be excluded.
5 Force the images to be rebuilt. (false by default unless --rerun-tasks was specified on the command-line).
6 Build images in parallel (true by default).
7 The template input file to use.
8 A working directory to which content may be output. Even if no output is expected, Packer will be executed with this as the working directory. the default is ${buildDir}/packer.
9 Add variables that will be passed to the packer process. Equivalent of -var on the command-line. Lazy evaluation is supported for the property values.
By default nothing is excluded and everything is included.

The task type also adds packer task extension so that global configuration that was set in the project extension called packer can be overriden on a per-task basis.

packerBuild {
    packer {
        executable version : '1.0.0' (1)
1 Override the version of Packer from the global setting