Partager via


Gradle@2 - Gradle v2 task

Build using a Gradle wrapper script.

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.


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 TFS/Team Services
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: **/build/test-results/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 = false. 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.


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.9 (JDK 9), 1.8 (JDK 8), 1.7 (JDK 7), 1.6 (JDK 6). 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.


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 Self-hosted agents must have capabilities that match the following demands to run jobs that use this task: java
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