Edit

Share via


Gradle@3 - Gradle v3 task

Use this task to build using a Gradle wrapper script.

Syntax

# Gradle v3
# Build using a Gradle wrapper script.
- task: Gradle@3
  inputs:
    gradleWrapperFile: 'gradlew' # string. Alias: wrapperScript. Required. Gradle wrapper. Default: gradlew.
    #workingDirectory: # string. Alias: cwd. Working directory. 
    #options: # string. Options. 
    tasks: 'build' # string. Required. Tasks. Default: build.
  # JUnit Test Results
    #publishJUnitResults: true # boolean. Publish to Azure Pipelines. Default: true.
    testResultsFiles: '**/TEST-*.xml' # string. Required when publishJUnitResults = true. Test results files. Default: **/TEST-*.xml.
    #testRunTitle: # string. Optional. Use when publishJUnitResults = true. Test run title. 
  # Code Coverage
    #codeCoverageToolOption: 'None' # 'None' | 'Cobertura' | 'JaCoCo'. Alias: codeCoverageTool. Code coverage tool. Default: None.
    codeCoverageClassFilesDirectories: 'build/classes/main/' # string. Alias: classFilesDirectories. Required when codeCoverageTool != None. Class files directories. Default: build/classes/main/.
    #codeCoverageClassFilter: # string. Alias: classFilter. Optional. Use when codeCoverageTool != None. Class inclusion/exclusion filters. 
    #codeCoverageFailIfEmpty: false # boolean. Alias: failIfCoverageEmpty. Optional. Use when codeCoverageTool != None. Fail when code coverage results are missing. Default: false.
    #codeCoverageGradle5xOrHigher: true # boolean. Alias: gradle5xOrHigher. Optional. Use when codeCoverageTool = JaCoCo. Gradle version >= 5.x. Default: true.
  # Advanced
    javaHomeOption: 'JDKVersion' # 'JDKVersion' | 'Path'. Alias: javaHomeSelection. Required. Set JAVA_HOME by. Default: JDKVersion.
    #jdkVersionOption: 'default' # 'default' | '1.17' | '1.11' | '1.10' | '1.9' | '1.8' | '1.7' | '1.6'. Alias: jdkVersion. Optional. Use when javaHomeSelection = JDKVersion. JDK version. Default: default.
    #jdkDirectory: # string. Alias: jdkUserInputPath. Required when javaHomeSelection = Path. JDK path. 
    #jdkArchitectureOption: 'x64' # 'x86' | 'x64'. Alias: jdkArchitecture. Optional. Use when jdkVersion != default. JDK architecture. Default: x64.
    #gradleOptions: '-Xmx1024m' # string. Alias: gradleOpts. Set GRADLE_OPTS. Default: -Xmx1024m.
  # Code Analysis
    #sonarQubeRunAnalysis: false # boolean. Alias: sqAnalysisEnabled. Run SonarQube or SonarCloud Analysis. Default: false.
    #sqGradlePluginVersionChoice: 'specify' # 'specify' | 'build'. Required when sqAnalysisEnabled = true. SonarQube scanner for Gradle version. Default: specify.
    #sonarQubeGradlePluginVersion: '2.6.1' # string. Alias: sqGradlePluginVersion. Required when sqAnalysisEnabled = true && sqGradlePluginVersionChoice = specify. SonarQube scanner for Gradle plugin version. Default: 2.6.1.
    #checkStyleRunAnalysis: false # boolean. Alias: checkstyleAnalysisEnabled. Run Checkstyle. Default: false.
    #findBugsRunAnalysis: false # boolean. Alias: findbugsAnalysisEnabled. Run FindBugs. Default: false.
    #pmdRunAnalysis: false # boolean. Alias: pmdAnalysisEnabled. Run PMD. Default: false.
    #spotBugsAnalysis: false # boolean. Alias: spotBugsAnalysisEnabled. Run SpotBugs. Default: false.
    #spotBugsGradlePluginVersionChoice: 'specify' # 'specify' | 'build'. Required when spotBugsAnalysisEnabled = true. Spotbugs plugin version. Default: specify.
    #spotbugsGradlePluginVersion: '4.7.0' # string. Required when spotBugsAnalysisEnabled = true && spotBugsGradlePluginVersionChoice = specify. Version number. Default: 4.7.0.
# Gradle v3
# Build using a Gradle wrapper script.
- task: Gradle@3
  inputs:
    gradleWrapperFile: 'gradlew' # string. Alias: wrapperScript. Required. Gradle wrapper. Default: gradlew.
    #workingDirectory: # string. Alias: cwd. Working directory. 
    #options: # string. Options. 
    tasks: 'build' # string. Required. Tasks. Default: build.
  # JUnit Test Results
    #publishJUnitResults: true # boolean. Publish to Azure Pipelines. Default: true.
    testResultsFiles: '**/TEST-*.xml' # string. Required when publishJUnitResults = true. Test results files. Default: **/TEST-*.xml.
    #testRunTitle: # string. Optional. Use when publishJUnitResults = true. Test run title. 
  # Code Coverage
    #codeCoverageToolOption: 'None' # 'None' | 'Cobertura' | 'JaCoCo'. Alias: codeCoverageTool. Code coverage tool. Default: None.
    codeCoverageClassFilesDirectories: 'build/classes/main/' # string. Alias: classFilesDirectories. Required when codeCoverageTool != None. Class files directories. Default: build/classes/main/.
    #codeCoverageClassFilter: # string. Alias: classFilter. Optional. Use when codeCoverageTool != None. Class inclusion/exclusion filters. 
    #codeCoverageFailIfEmpty: false # boolean. Alias: failIfCoverageEmpty. Optional. Use when codeCoverageTool != None. Fail when code coverage results are missing. Default: false.
    #codeCoverageGradle5xOrHigher: true # boolean. Alias: gradle5xOrHigher. Optional. Use when codeCoverageTool = JaCoCo. Gradle version >= 5.x. Default: true.
  # Advanced
    javaHomeOption: 'JDKVersion' # 'JDKVersion' | 'Path'. Alias: javaHomeSelection. Required. Set JAVA_HOME by. Default: JDKVersion.
    #jdkVersionOption: 'default' # 'default' | '1.11' | '1.10' | '1.9' | '1.8' | '1.7' | '1.6'. Alias: jdkVersion. Optional. Use when javaHomeSelection = JDKVersion. JDK version. Default: default.
    #jdkDirectory: # string. Alias: jdkUserInputPath. Required when javaHomeSelection = Path. JDK path. 
    #jdkArchitectureOption: 'x64' # 'x86' | 'x64'. Alias: jdkArchitecture. Optional. Use when jdkVersion != default. JDK architecture. Default: x64.
    #gradleOptions: '-Xmx1024m' # string. Alias: gradleOpts. Set GRADLE_OPTS. Default: -Xmx1024m.
  # Code Analysis
    #sonarQubeRunAnalysis: false # boolean. Alias: sqAnalysisEnabled. Run SonarQube or SonarCloud Analysis. Default: false.
    #sqGradlePluginVersionChoice: 'specify' # 'specify' | 'build'. Required when sqAnalysisEnabled = true. SonarQube scanner for Gradle version. Default: specify.
    #sonarQubeGradlePluginVersion: '2.6.1' # string. Alias: sqGradlePluginVersion. Required when sqAnalysisEnabled = true && sqGradlePluginVersionChoice = specify. SonarQube scanner for Gradle plugin version. Default: 2.6.1.
    #checkStyleRunAnalysis: false # boolean. Alias: checkstyleAnalysisEnabled. Run Checkstyle. Default: false.
    #findBugsRunAnalysis: false # boolean. Alias: findbugsAnalysisEnabled. Run FindBugs. Default: false.
    #pmdRunAnalysis: false # boolean. Alias: pmdAnalysisEnabled. Run PMD. Default: false.
    #spotBugsAnalysis: false # boolean. Alias: spotBugsAnalysisEnabled. Run SpotBugs. Default: false.
    #spotBugsGradlePluginVersionChoice: 'specify' # 'specify' | 'build'. Required when spotBugsAnalysisEnabled = true. Spotbugs plugin version. Default: specify.
    #spotbugsGradlePluginVersion: '4.7.0' # string. Required when spotBugsAnalysisEnabled = true && spotBugsGradlePluginVersionChoice = specify. Version number. Default: 4.7.0.

Inputs

gradleWrapperFile - Gradle wrapper
Input alias: wrapperScript. string. Required. Default value: gradlew.

Specifies the gradlew wrapper's location within the repository that will be used for the build. Agents on Windows (including Microsoft-hosted agents) must use the gradlew.bat wrapper. Agents on Linux or macOS can use the gradlew shell script. Learn more about the Gradle Wrapper. If the Gradle wrapper isn't in the root directory, specify the path to the wrapper script. For example, subdir/gradlew.


workingDirectory - Working directory
Input alias: cwd. string.

Specifies the working directory to run the Gradle build. The task uses the repository root directory if the working directory is not specified.


options - Options
string.

Specifies the command line options that will be passed to the Gradle wrapper. See Gradle Command Line for more information.


tasks - Tasks
string. Required. Default value: build.

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 for more information.


publishJUnitResults - Publish to Azure Pipelines
boolean. Default value: true.

Publishes JUnit test results produced by the Gradle build to Azure Pipelines. The task publishes each test results file matching Test Results Files as a test run in Azure Pipelines.


testResultsFiles - Test results files
string. Required when publishJUnitResults = true. Default value: **/TEST-*.xml.

The file path for test results. Wildcards can be used. For example, **/TEST-*.xml for all XML files whose name starts with TEST-.


testRunTitle - Test run title
string. Optional. Use when publishJUnitResults = true.

Provides a name for the JUnit test case results for this build.


codeCoverageToolOption - Code coverage tool
Input alias: codeCoverageTool. string. Allowed values: None, Cobertura, JaCoCo. Default value: None.

Specifies a code coverage tool to determine the code that is covered by the test cases for the build.


codeCoverageClassFilesDirectories - Class files directories
Input alias: classFilesDirectories. string. Required when codeCoverageTool != None. Default value: build/classes/main/.

The comma-separated list of directories containing class files and archive files (.jar, .war, and more). Code coverage is reported for class files in these directories. Normally, the task searches classes under build/classes/java/main (for Gradle 4+), which is the default class directory for Gradle builds.


codeCoverageClassFilter - Class inclusion/exclusion filters
Input alias: classFilter. string. Optional. Use when codeCoverageTool != None.

The comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,-:my.app*.*.


codeCoverageFailIfEmpty - Fail when code coverage results are missing
Input alias: failIfCoverageEmpty. boolean. Optional. Use when codeCoverageTool != None. Default value: false.

Fails the build if code coverage did not produce any results to publish.


codeCoverageGradle5xOrHigher - Gradle version >= 5.x
Input alias: gradle5xOrHigher. boolean. Optional. Use when codeCoverageTool = JaCoCo. Default value: true.

Set this to 'true' if gradle version is >= 5.x.


javaHomeOption - Set JAVA_HOME by
Input alias: javaHomeSelection. string. Required. Allowed values: JDKVersion (JDK Version), Path. Default value: JDKVersion.

Sets JAVA_HOME by selecting a JDK version that the task discovers during builds or by manually entering a JDK path.


jdkVersionOption - JDK version
Input alias: jdkVersion. string. Optional. Use when javaHomeSelection = JDKVersion. Allowed values: default, 1.17 (JDK 17), 1.11 (JDK 11), 1.10 (JDK 10 (out of support)), 1.9 (JDK 9 (out of support)), 1.8 (JDK 8), 1.7 (JDK 7), 1.6 (JDK 6 (out of support)). Default value: default.

Attempts to discover the path to the selected JDK version and set JAVA_HOME accordingly.


jdkVersionOption - JDK version
Input alias: jdkVersion. string. Optional. Use when javaHomeSelection = JDKVersion. Allowed values: default, 1.11 (JDK 11), 1.10 (JDK 10 (out of support)), 1.9 (JDK 9 (out of support)), 1.8 (JDK 8), 1.7 (JDK 7), 1.6 (JDK 6 (out of support)). Default value: default.

Attempts to discover the path to the selected JDK version and set JAVA_HOME accordingly.


jdkDirectory - JDK path
Input alias: jdkUserInputPath. string. Required when javaHomeSelection = Path.

Sets JAVA_HOME to the given path.


jdkArchitectureOption - JDK architecture
Input alias: jdkArchitecture. string. Optional. Use when jdkVersion != default. Allowed values: x86, x64. Default value: x64.

Supplies the JDK architecture (x86 or x64).


gradleOptions - Set GRADLE_OPTS
Input alias: gradleOpts. string. Default value: -Xmx1024m.

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.


sonarQubeRunAnalysis - Run SonarQube or SonarCloud Analysis
Input alias: sqAnalysisEnabled. boolean. Default value: false.

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.


sqGradlePluginVersionChoice - SonarQube scanner for Gradle version
string. Required when sqAnalysisEnabled = true. Allowed values: specify (Specify version number), build (Use plugin applied in your build.gradle). Default value: specify.

Specifies the SonarQube Gradle plugin version to use. Declare the version in the Gradle configuration file, or specify a version with this string.


sonarQubeGradlePluginVersion - SonarQube scanner for Gradle plugin version
Input alias: sqGradlePluginVersion. string. Required when sqAnalysisEnabled = true && sqGradlePluginVersionChoice = specify. Default value: 2.6.1.

Contains the version number of the SonarQube Gradle plugin.


checkStyleRunAnalysis - Run Checkstyle
Input alias: checkstyleAnalysisEnabled. boolean. Default value: false.

Runs the Checkstyle tool with the default Sun checks. Results are uploaded as build artifacts.


findBugsRunAnalysis - Run FindBugs
Input alias: findbugsAnalysisEnabled. boolean. Default value: false.

Uses the FindBugs static analysis tool to look for bugs in the code. Results are uploaded as build artifacts. In Gradle 6.0, this plugin was removed. Use the SpotBugs plugin instead.


pmdRunAnalysis - Run PMD
Input alias: pmdAnalysisEnabled. boolean. Default value: false.

Uses the PMD Java static analysis tool to look for bugs in the code. The results are uploaded as build artifacts.


spotBugsAnalysis - Run SpotBugs
Input alias: spotBugsAnalysisEnabled. boolean. Default value: false.

Runs spotBugs when true. This plugin works with Gradle v5.6 or later. Learn more about using the SpotBugs Gradle plugin. The plugin may work in an unexpected way or may not work at all with an earlier Gradle version.


spotBugsGradlePluginVersionChoice - Spotbugs plugin version
string. Required when spotBugsAnalysisEnabled = true. Allowed values: specify (Specify version number), build (Use plugin applied in your build.gradle). Default value: specify.

Specifies the SpotBugs Gradle plugin version to use. The version can be declared in the Gradle configuration file, or the version can be specified in this string.


spotbugsGradlePluginVersion - Version number
string. Required when spotBugsAnalysisEnabled = true && spotBugsGradlePluginVersionChoice = specify. Default value: 4.7.0.

Contains the version number of the SpotBugs Gradle plugin.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

Configuration of the SonarQube analysis was moved to the SonarQube or SonarCloud extensions in the task Prepare Analysis Configuration.

Use this task to build using a Gradle wrapper script.

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 -Dhttp.socketTimeout=60000 -Dhttp.connectionTimeout=60000 to Options. This increases the timeout from 10 seconds to 1 minute.

Examples

Build your Java app with Gradle

Requirements

Requirement Description
Pipeline types YAML, Classic build
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 1.91.0 or greater
Task category Build