The Gradle plugin

This plugin is used for building parts that use gradle.

The gradle build system is a popular build tool used to build Java projects. The plugin requires that gradle’s build.gradle file exists in the root of the source tree.

Plugin-specific keywords

(list of strings)
flags to pass to the build using the gradle semantics for parameters.
The ‘jar’ option is automatically passed and will be passed in as the last parameter.
Essentially you can include any gradle command line options such as ‘-x test’ ‘–debug’ as a comma separated list.

    [-xtest, --debug]

Note: your options may not contain spaces!

(string; default: ‘build/libs’)
Informs snapcraft where your build.gradle will place the generated files.
The output directory where the resulting jar or war files from gradle[w]
are generated.
You should normally NOT include this option unless your build.gradle is placing the output files in an unusual place.


Building Wars
The gradle plugin current (in my opinion) has a bug in that it always run the ‘jar’ task rather than the ‘build’ task (but I’m new to gradle so maybe I’m confused). The result is that even if your build.gradle is configured to build a war you will actually end up with a jar.
To fix this problem include a gradle-option keyword with the ‘war’ task.


  gradle-options: [-xtest, war]

The jar file will still be generated but so will your war file.


** NOTE this keywoard is not yet released **
(list of strings)
list of tasks to pass gradle after the ‘gradle-options’.

Note: I’ve push a PR #2135 which aims to fix the above war build issue by adding this new gradle-tasks keyword.
Once/IF the PR is merged you will be able to specify the gradle-tasks keyword

When the gradle-tasks keyword is used the default ‘jar’ task is not passed. This allows you to control exactly which tasks gradle executes.

  gradle-options: [-xtest]
  gradle-tasks: [check, war]

If the gradle-tasks keyword is used then the default ‘jar’ task will not be run.

gradelw vs gradle
When the gradle plugin runs it will search for ‘gradlew’ in the directory you run snapcraft from. If it finds gradelw then it will run the build using gradlew. If gradelw doesn’t exist then it will fall back to using gradle.
Using gradlew is recommended.
If you are looking to run the latest version of gradle then make certain that gradlew is present.

Proxy settings

The gradle plugin will automatically go looking for environment variables that contain proxy settings.
The environment variable names that it looks for are:



If found these variables will be passed as options to gradle.


    plugin: gradle
    source-type: git
      [-xtest, war]   # supress running of tests and run the war task

Examples on GitHub

Last updated 11 months ago. Help improve this document in the forum.