title | description | ms.assetid | ms.reviewer | ms.topic | ms.date | monikerRange |
---|---|---|---|---|---|---|
Build Java apps |
Automatically building Java apps with Azure Pipelines, Azure DevOps, & Team Foundation Server |
604822a1-a46b-49d3-ad30-8152e9420758 |
dastahel |
quickstart |
08/30/2019 |
>= tfs-2017 |
[!INCLUDE version-tfs-2017-rtm]
::: moniker range="<= tfs-2018"
Note
This guidance uses YAML-based pipelines available in Azure Pipelines. For TFS, use tasks that correspond to those used in the YAML below. ::: moniker-end
This guidance explains how to automatically build Java projects. (If you're working on an Android project, see Build, test, and deploy Android apps.)
::: moniker range=">=azure-devops-2020"
Are you new to Azure Pipelines? If so, then we recommend you try this section to create before moving on to other sections.
::: moniker-end
::: moniker range=">=azure-devops-2020"
[!INCLUDE include]
::: moniker-end
::: moniker range="azure-devops-2019"
Import this repo into your Git repo in Azure DevOps Server 2019:
::: moniker-end
::: moniker range="< azure-devops-2019"
Import this repo into your Git repo in TFS:
::: moniker-end
https://github.com/MicrosoftDocs/pipelines-java
::: moniker range=">=azure-devops-2020"
[!INCLUDE include]
[!INCLUDE include]
::: moniker-end
::: moniker range=">=azure-devops-2020"
[!INCLUDE include]
When the Configure tab appears, select Maven.
-
When your new pipeline appears, take a look at the YAML to see what it does. When you're ready, select Save and run.
-
You're prompted to commit a new azure-pipelines.yml file to your repository. After you're happy with the message, select Save and run again.
If you want to watch your pipeline in action, select the build job.
You just created and ran a pipeline that we automatically created for you, because your code appeared to be a good match for the Maven template.
You now have a working YAML pipeline (
azure-pipelines.yml
) in your repository that's ready for you to customize! -
When you're ready to make changes to your pipeline, select it in the Pipelines page, and then Edit the
azure-pipelines.yml
file. -
See the sections below to learn some of the more common ways to customize your pipeline.
::: moniker-end
::: moniker range="< azure-devops"
-
Create a pipeline (if you don't know how, see Create your first pipeline, and for the template select Maven. This template automatically adds the tasks you need to build the code in the sample repository.
-
Save the pipeline and queue a build. When the Build #nnnnnnnn.n has been queued message appears, select the number link to see your pipeline in action.
You now have a working pipeline that's ready for you to customize!
-
When you're ready to make changes to your pipeline, Edit it.
-
See the sections below to learn some of the more common ways to customize your pipeline.
::: moniker-end
::: moniker range=">=azure-devops-2020"
You can use Azure Pipelines to build Java apps without needing to set up any infrastructure of your own. You can build on Windows, Linux, or MacOS images. The Microsoft-hosted agents in Azure Pipelines have modern JDKs and other tools for Java pre-installed. To know which versions of Java are installed, see Microsoft-hosted agents.
Update the following snippet in your azure-pipelines.yml
file to select the appropriate image.
pool:
vmImage: 'ubuntu-16.04' # other options: 'macOS-10.14', 'vs2017-win2016'
See Microsoft-hosted agents for a complete list of images.
As an alternative to using Microsoft-hosted agents, you can set up self-hosted agents with Java installed. You can also use self-hosted agents to save additional time if you have a large repository or you run incremental builds.
::: moniker-end
::: moniker range="< azure-devops"
Your builds run on a self-hosted agent. Make sure that you have Java installed on the agent.
::: moniker-end
::: moniker range=">= azure-devops-2019"
To build with Maven, add the following snippet to your azure-pipelines.yml
file. Change values, such as the path to your pom.xml
file, to match your project configuration. See the Maven task for more about these options.
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
goals: 'package'
Adjust the mavenPomFile
value if your pom.xml
file isn't in the root of the repository. The file path value should be relative to the root of the repository, such as IdentityService/pom.xml
or $(system.defaultWorkingDirectory)/IdentityService/pom.xml
.
Set the goals value to a space-separated list of goals for Maven to execute, such as clean package
.
For details about common Java phases and goals, see Apache's Maven documentation.
To build with Gradle, add the following snippet to your azure-pipelines.yml
file. See the Gradle task for more about these options.
steps:
- task: Gradle@2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
The version of Gradle installed on the agent machine will be used unless your repository's gradle/wrapper/gradle-wrapper.properties
file has a distributionUrl
property that specifies a different Gradle version to download and use during the build.
Adjust the workingDirectory
value if your gradlew
file isn't in the root of the repository.
The directory value should be relative to the root of the repository, such as IdentityService
or $(system.defaultWorkingDirectory)/IdentityService
.
Adjust the gradleWrapperFile
value if your gradlew
file isn't in the root of the repository. The file path value should be relative to the root of the repository, such as IdentityService/gradlew
or $(system.defaultWorkingDirectory)/IdentityService/gradlew
.
Adjust the tasks value for the tasks that Gradle should execute, such as build
or check
.
For details about common Java Plugin tasks for Gradle, see Gradle's documentation.
To build with Ant, add the following snippet to your azure-pipelines.yml
file. Change values, such as the path to your build.xml
file, to match your project configuration. See the Ant task for more about these options.
steps:
- task: Ant@1
inputs:
workingDirectory: ''
buildFile: 'build.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
To build with a command line or script, add one of the following snippets to your azure-pipelines.yml
file.
The script:
step runs an inline script using Bash on Linux and macOS and Command Prompt on Windows. For details, see the Bash or Command line task.
steps:
- script: |
echo Starting the build
mvn package
displayName: 'Build with Maven'
This snippet runs a script file that is in your repository. For details, see the Shell Script, Batch script, or PowerShell task.
steps:
- task: ShellScript@2
inputs:
scriptPath: 'build.sh'
After you've built and tested your app, you can upload the build output to Azure Pipelines or TFS, create and publish a Maven package, or package the build output into a .war/jar file to be deployed to a web application.
::: moniker-end
::: moniker range=">=azure-devops-2020"
Next we recommend that you learn more about creating a CI/CD pipeline for the deployment target you choose:
- Build and deploy to a Java web app
- Build and deploy Java to Azure Functions
- Build and deploy Java to Azure Kubernetes service
::: moniker-end