Gradle task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015

Use this task to build using a Gradle wrapper script.

YAML snippet

# Gradle
# Build using a Gradle wrapper script
- task: Gradle@2
  inputs:
    #gradleWrapperFile: 'gradlew' 
    #cwd: # Optional
    #options: # Optional
    #tasks: 'build' # A list of tasks separated by spaces, such as 'build test'
    #publishJUnitResults: true 
    #testResultsFiles: '**/TEST-*.xml' # Required when publishJUnitResults == True
    #testRunTitle: # Optional
    #codeCoverageToolOption: 'None' # Optional. Options: none, cobertura, jaCoCo
    #codeCoverageClassFilesDirectories: 'build/classes/main/' # Required when codeCoverageToolOption == False
    #codeCoverageClassFilter: # Optional. Comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,-:my.app*.*
    #codeCoverageFailIfEmpty: false # Optional
    #javaHomeOption: 'JDKVersion' # Options: jDKVersion, path
    #jdkVersionOption: 'default' # Optional. Options: default, 1.11, 1.10, 1.9, 1.8, 1.7, 1.6
    #jdkDirectory: # Required when javaHomeOption == Path
    #jdkArchitectureOption: 'x64' # Optional. Options: x86, x64
    #gradleOptions: '-Xmx1024m' # Optional
    #sonarQubeRunAnalysis: false 
    #sqGradlePluginVersionChoice: 'specify' # Required when sonarQubeRunAnalysis == True# Options: specify, build
    #sonarQubeGradlePluginVersion: '2.6.1' # Required when sonarQubeRunAnalysis == True && SqGradlePluginVersionChoice == Specify
    #checkStyleRunAnalysis: false # Optional
    #findBugsRunAnalysis: false # Optional
    #pmdRunAnalysis: false # Optional

Arguments


Default value: true
Argument Description
wrapperScript
Gradle Wrapper

(Required) The location in the repository of the gradlew wrapper used for the build. For agents on Windows (including Microsoft-hosted agents), you must use the gradlew.bat wrapper. Agents on Linux or macOS can use the gradlew shell script.

See The Gradle Wrapper.


Default value: gradlew
Argument aliases: gradleWrapperFile
options
Options

(Optional) Specify any command line options you want to pass to the Gradle wrapper.

See Gradle Command Line.

tasks
Tasks

(Required) The task(s) for Gradle to execute. A list of task names should be separated by spaces and can be taken from gradlew tasks issued from a command prompt.

See Gradle Build Script Basics.


Default value: build
JUnit Test Results
publishJUnitResults
Publish to Azure Pipelines
(Required) Select this option to publish JUnit Test results produced by the Gradle build to Azure Pipelines/TFS.
testResultsFiles
Test results files
(Required) Test results files path. Wildcards can be used. For example, */TEST-.xml for all xml files whose name starts with TEST-."
Default value: **/TEST-*.xml
testRunTitle
Test run title
(Optional) Assign a title for the JUnit test case results for this build.
Code Coverage
codeCoverageTool
Code coverage tool
(Optional) Choose a code coverage tool to determine the code that is covered by the test cases for the build.
Default value: None
Argument aliases: codeCoverageToolOption
classFilesDirectories
Class files directories
(Required) Comma-separated list of directories containing class files and archive files (JAR, WAR, etc.). Code coverage is reported for class files in these directories. Normally, classes under `build/classes/main` are searched, which is the default class directory for Gradle builds
Default value: build/classes/main/
Argument aliases: codeCoverageClassFilesDirectories
classFilter
Class inclusion/exclusion filters
(Optional) Comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,-:my.app*.*."
Argument aliases: codeCoverageClassFilter
failIfCoverageEmpty
Fail when code coverage results are missing
(Optional) Fail the build if code coverage did not produce any results to publish
Default value: false
Argument aliases: codeCoverageFailIfEmpty
Advanced
cwd
Working directory
(Optional) Working directory in which to run the Gradle build. If not specified, the repository root directory is used
javaHomeSelection
Set JAVA_HOME by
(Required) Sets JAVA_HOME either by selecting a JDK version that will be discovered during builds or by manually entering a JDK path
Default value: JDKVersion
Argument aliases: javaHomeOption
jdkVersion
JDK version
(Optional) Will attempt to discover the path to the selected JDK version and set JAVA_HOME accordingly
Argument aliases: jdkDirectory
jdkUserInputPath
JDK path
(Required) Sets JAVA_HOME to the given path
Default value: default
Argument aliases: jdkVersionOption
jdkArchitecture
JDK Architecture
(Optional) Optionally supply the architecture (x86, x64) of JDK.
Default value: x64
Argument aliases: jdkArchitectureOption
gradleOpts
Set GRADLE_OPTS
(Optional) Sets the GRADLE_OPTS environment variable, which is used to send command-line arguments to start the JVM. The xmx flag specifies the maximum memory available to the JVM.
Default value: -Xmx1024m
Argument aliases: gradleOptions
Code Analysis
sqAnalysisEnabled
Run SonarQube or SonarCloud Analysis
(Required) This option has changed from version 1 of the Gradle task to use the SonarQube and SonarCloud marketplace extensions. Enable this option to run SonarQube or SonarCloud analysis after executing tasks in the Tasks field. You must also add a Prepare Analysis Configuration task from one of the extensions to the build pipeline before this Gradle task
Default value: false
Argument aliases: sonarQubeRunAnalysis
sqGradlePluginVersionChoice
SonarQube scanner for Gradle version
(Required) The SonarQube Gradle plugin version to use. You can declare it in your Gradle configuration file, or specify a version here
Default value: specify
sqGradlePluginVersion
SonarQube scanner for Gradle plugin version
(Required) Refer for all available versions
Default value: 2.6.1
Argument aliases: sonarQubeGradlePluginVersion
checkstyleAnalysisEnabled
Run Checkstyle
(Optional) Run the Checkstyle tool with the default Sun checks. Results are uploaded as build artifacts.
Default value: false
Argument aliases: checkStyleRunAnalysis
findbugsAnalysisEnabled
Run FindBugs
(Optional) Use the FindBugs static analysis tool to look for bugs in the code. Results are uploaded as build artifacts
Default value: false
Argument aliases: findBugsRunAnalysis
pmdAnalysisEnabled
Run PMD
(Optional) Use the PMD Java static analysis tool to look for bugs in the code. Results are uploaded as build artifacts
Default value: false
Argument aliases: pmdRunAnalysis
Control options

Example

Build your Java app with Gradle

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

FAQ

How do I generate a wrapper from my Gradle project?

The Gradle wrapper allows the build agent to download and configure the exact Gradle environment that is checked into the repository without having any software configuration on the build agent itself other than the JVM.

  1. Create the Gradle wrapper by issuing the following command from the root project directory where your build.gradle resides:

    jamal@fabrikam> gradle wrapper

  2. Upload your Gradle wrapper to your remote repository.

    There is a binary artifact that is generated by the gradle wrapper ( located at gradle/wrapper/gradle-wrapper.jar ). This binary file is small and doesn't require updating. If you need to change the Gradle configuration run on the build agent, you update the gradle-wrapper.properties.

    The repository should look something like this:

|-- gradle/
    `-- wrapper/
        `-- gradle-wrapper.jar
        `-- gradle-wrapper.properties
|-- src/
|-- .gitignore
|-- build.gradle
|-- gradlew
|-- gradlew.bat

How do I fix timeouts when downloading dependencies?

To fix errors such as Read timed out when downloading dependencies, users of Gradle 4.3+ can change the timeout by adding to Options -Dhttp.socketTimeout=60000 -Dhttp.connectionTimeout=60000. This increases the timeout from 10 seconds to 1 minute.

Do I need an agent?

You need at least one agent to run your build or release.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.