Maven task

Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015

Use this task to build your Java code.

Demands

The build agent must have the following capability:

  • Maven

YAML snippet

# Maven
# Build, test, and deploy with Apache Maven
- task: Maven@3
  inputs:
    #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. Enabling code coverage inserts the `clean` goal into the Maven goals list when Maven runs.
    #codeCoverageClassFilter: # Optional. Comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,-:my.app*.*
    #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 
    #effectivePomSkip: false 
    #sonarQubeRunAnalysis: false 
    #sqMavenPluginVersionChoice: 'latest' # Required when sonarQubeRunAnalysis == True# Options: latest, pom
    #checkStyleRunAnalysis: false # Optional
    #pmdRunAnalysis: false # Optional
    #findBugsRunAnalysis: false # Optional

Arguments

Argument Description
mavenPOMFile
Maven POM file
(Required) Relative path from the repository root to the Maven POM file. See Introduction to the POM.
Default value: pom.xml
Argument aliases: mavenPomFile
goals
Goal(s)
(Optional) 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.
Default value: package
options
Options
(Optional) Specify any Maven command-line options you want to use.
publishJUnitResults
Publish to Azure Pipelines
(Required) Select this option to publish JUnit test results produced by the Maven build to Azure Pipelines. Each test results file matching Test Results Files will be published as a test run in Azure Pipelines.
Default value: true
testResultsFiles
Test results files
(Required) Specify the path and pattern of test results files to publish. Wildcards can be used (more information). For example, */TEST-.xml for all XML files whose name starts with TEST-. If no root path is specified, files are matched beneath the default working directory, the value of which is available in the variable: $(System.DefaultWorkingDirectory).
For example, a value of ' /TEST- .xml' will actually result in matching files from '$(System.DefaultWorkingDirectory)/ /TEST-.xml'.
Default value: **/surefire-reports/TEST-*.xml
testRunTitle
Test run title
(Optional) Provide a name for the test run.
codeCoverageTool
Code coverage tool
(Optional) Select the code coverage tool. Enabling code coverage inserts the clean goal into the Maven goals list when Maven runs.
Default value: None
Argument aliases: codeCoverageToolOption
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
classFilesDirectories
Class files directories
(Optional) This field is required for a multi-module project. Specify a comma-separated list of relative paths from the Maven POM file to directories containing class files and archive files (JAR, WAR, etc.). Code coverage is reported for class files in these directories.
For example: target/classes,target/testClasses.
Argument aliases: codeCoverageClassFilesDirectories
srcDirectories
Source files directories
(Optional) This field is required for a multi-module project. Specify a comma-separated list of relative paths from the Maven POM file to source code directories. Code coverage reports will use these to highlight source code.
For example: src/java,src/Test.
Argument aliases: codeCoverageSourceDirectories
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
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.
Default value: default
Argument aliases: jdkVersionOption
jdkUserInputPath
JDK path
(Required) Sets JAVA_HOME to the given path.
Argument aliases: jdkDirectory
jdkArchitecture
JDK architecture
(Optional) Optionally supply the architecture (x86, x64) of the JDK.
Default value: x64
Argument aliases: jdkArchitectureOption
mavenVersionSelection
Maven version
(Required) Uses either the default Maven version or the version in the specified custom path.
Default value: Default
Argument aliases: mavenVersionOption
mavenPath
Maven path
(Required) Supply the custom path to the Maven installation (e.g., /usr/share/maven).
Argument aliases: mavenDirectory
mavenSetM2Home
Set M2_HOME variable
(Required) Sets the M2_HOME variable to a custom Maven installation path.
Default value: false
mavenOpts
Set MAVEN_OPTS to
(Optional) Sets the MAVEN_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: mavenOptions
mavenFeedAuthenticate
Authenticate built-in Maven feeds
(Required) Automatically authenticate Maven feeds from Azure Artifacts. If built-in Maven feeds are not in use, deselect this option for faster builds.
Default value: false
Argument aliases: mavenAuthenticateFeed
skipEffectivePom
Skip generating effective POM while authenticating built-in feeds
(Required) Authenticate built-in Maven feeds using the POM only, allowing parent POMs in Azure Artifacts/Azure DevOps Server [Package Management] feeds.
Default value: false
Argument aliases: effectivePomSkip
sqAnalysisEnabled
Run SonarQube or SonarCloud analysis
(Required) This option has changed from version 1 of the Maven task to use the SonarQube and SonarCloud marketplace extensions. Enable this option to run SonarQube or SonarCloud analysis after executing goals in the Goals field. The install or package goal should run first. You must also add a Prepare Analysis Configuration task from one of the extensions to the build pipeline before this Maven task.
Default value: false
Argument aliases: sonarQubeRunAnalysis
sqMavenPluginVersionChoice<>SonarQube scanner for Maven version (Required) The SonarQube Maven plugin version to use. You can use latest version, or rely on the version in your pom.xml.
Default value: latest
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
pmdAnalysisEnabled
Run PMD
(Optional) Use the PMD static analysis tool to look for bugs in the code. Results are uploaded as build artifacts.
Default value: false
Argument aliases: pmdRunAnalysis
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
Control options

Important

When using the -q option in your MAVEN_OPTS, an effective pom won't be generated correctly and Azure Artifacts feeds may not be able to be authenticated.

Example

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.

FAQ

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.