Maven task
TFS 2017 | TFS 2015
Use this task to build your Java code.
Demands
The build agent must have the following capability:
- Maven
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. |
allowBrokenSymbolicLinks Test results files |
(Optional) Set false to fail build when the task meets broken symbolic links during publishing tests. It has an effect only if publishJUnitResults is set
true
Default value: true Argument aliases: allowBrokenSymlink |
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. Please note that if you already have java installed on agent machine - you can specify it by setting up 'javaHomeOption' as 'path', and 'jdkDirectory' - as a path to jdk installed directory. 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. Note: If running on an agent not hosted by Microsoft, and the requested Java version is not the one indicated by the JAVA_HOME variable set on the agent machine, the task will rely on the variable JAVA_HOME_<version>_<arch> (e.g. JAVA_HOME_8_X64 ), to locate the necessary JDK. Ensure this variable is set on self-hosted agents for any version and architecture of the JDK that may be requested by this parameter and/or by jdkArchitecture .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. Note: If running on an agent not hosted by Microsoft, and the requested Java architecture is not the one indicated by the JAVA_HOME variable set on the agent machine, the task will rely on the variable JAVA_HOME_<version>_<arch> (e.g. JAVA_HOME_8_X64 ), to locate the necessary JDK. Ensure this variable is set on self-hosted agents for any version and architecture of the JDK that may be requested by this parameter and/or by jdkVersion .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. If no checkstyle configuration is specified in the pom.xml file, default Sun checks will be used. 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 |
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.
My NuGet push task is failing with the following error: "Error: unable to get local issuer certificate". How can I fix this?
This can be fixed by adding a trusted root certificate. You can either add the NODE_EXTRA_CA_CERTS=file
environment variable to your build agent, or you can add the NODE.EXTRA.CA.CERTS=file
task variable in your pipeline. See Node.js documentation for more details about this variable. See Set variables in a pipeline for instructions on setting a variable in your pipeline.
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.