Gradle@4 - Gradle v4 task
Build using a Gradle wrapper script.
Important
The built-in code coverage option is removed from the Gradle
task starting with Gradle@4
. For more information, see Remarks.
Syntax
# Gradle v4
# Build using a Gradle wrapper script.
- task: Gradle@4
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.
# 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.
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.
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.
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
The built-in code coverage option is removed from the Gradle
task starting with Gradle@4
. To use code coverage with Gradle in your pipeline:
- Specify code coverage plugins in your
build.gradle
file. For more information, see Gradle code analysis options. - Use the PublishCodeCoverageResults@2 task in your pipeline after the
GRadle@2
task.
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.
Create the Gradle wrapper by issuing the following command from the root project directory where your build.gradle resides:
jamal@fabrikam> gradle wrapper
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 thegradle-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 |