Maven task

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

Use this task in a build or release pipeline to build your Java code.


The build agent must have the following capability:

  • Maven

YAML snippet

# Maven
# Build with Apache Maven
- task: Maven@3
    #mavenPomFile: 'pom.xml' 
    #goals: 'package' # Optional
    #options: # Optional
    #publishJUnitResults: true 
    #testResultsFiles: '**/surefire-reports/TEST-*.xml' # Required when publishJUnitResults == True
    #testRunTitle: # Optional
    #codeCoverageToolOption: 'None' # Optional. Options: none, cobertura, jaCoCo
    #codeCoverageClassFilter: # Optional
    #codeCoverageClassFilesDirectories: # Optional
    #codeCoverageSourceDirectories: # Optional
    #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
    #mavenVersionOption: 'Default' # Options: default, path
    #mavenDirectory: # Required when mavenVersionOption == Path
    #mavenSetM2Home: false # Required when mavenVersionOption == Path
    #mavenOptions: '-Xmx1024m' # Optional
    #mavenAuthenticateFeed: false 
    #sonarQubeRunAnalysis: false 
    #sqMavenPluginVersionChoice: 'latest' # Required when sonarQubeRunAnalysis == True# Options: latest, pom
    #checkStyleRunAnalysis: false # Optional
    #pmdRunAnalysis: false # Optional
    #findBugsRunAnalysis: false # Optional


Argument Description
Maven POM file

Relative path from the repo root to the Maven POM .xml file.

See Introduction to the POM.

Options Specify any Maven options you want to use.

In most cases, set this to package to compile your code and package it into a .war file. If you leave this argument blank, the build will fail.

See Introduction to the Maven build lifecycle.

JUnit Test Results
Publish to Azure Pipelines/TFS Select this option to publish JUnit Test results produced by the Maven build to Azure Pipelines/TFS.
Test Results Files Test results files path. Wildcards can be used. For example, **/TEST-*.xml for all xml files whose name starts with TEST-."
JDK Version Will attempt to discover the path to the selected JDK version and set JAVA_HOME accordingly.
JDK Architecture Optionally supply the architecture (x86, x64) of JDK.
Code Analysis
Run SonarQube Analysis Select if you want to run a SonarQube analysis. See The Maven build task now simplifies SonarQube analysis.
Run PMD Analysis Select if you want to perform a PMD static analysis. A build result page for each .pom file is shown on the Artifacts tab of the completed build. See The Maven build task now supports PMD analysis out of the box.
Control options


Build and Deploy your Java application to an Azure Web App

Open source

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

Q & A

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

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.