简体   繁体   English

如何在Azure Pipelines for CI / CD中使用较新版本的Maven进行构建

[英]How to use newer versions of Maven for builds in Azure Pipelines for CI/CD

I need Maven version 3.5.3 or above to build my project hosted on github. 我需要Maven版本3.5.3或更高版本来构建我在github上托管的项目。 The default version for maven used in Azure pipelines CI/CD is 3.3.9. Azure管道CI / CD中使用的maven的默认版本是3.3.9。 I can see that there is a way to install a different version of java using Java tool installer . 我可以看到有一种方法可以使用Java工具安装程序安装不同版本的java。 I don't find such an option in their documentation for maven. 我在maven的文档中找不到这样的选项。

But for maven it is possible to specify the 但对于maven ,可以指定

mavenVersionOption: 'Default' # Options: default, path
mavenDirectory: # Required when mavenVersionOption == Path

But being a newbie I don't understand how to install maven and specify a path here. 但作为一个新手,我不明白如何安装maven并在这里指定路径。

Any help on how to use a different version for my maven build in Azure pipelines CI/CD would be appreciated. 有关如何在Azure管道CI / CD中使用不同版本的maven构建的任何帮助将不胜感激。

Since I am on an Ubuntu environment I was able to get this running by using a script to download maven and by setting the path for maven as follows: 由于我在Ubuntu环境中,我能够通过使用脚本来下载maven并通过设置maven的路径来运行,如下所示:

pool:
  vmImage: 'Ubuntu 16.04'

steps:
- script: 'wget http://www-eu.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.zip'

- task: ExtractFiles@1
  inputs:
      archiveFilePatterns: 'apache-maven-3.5.4-bin.zip'
      destinationFolder: '$(build.sourcesdirectory)/maven'

- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    goals: 'clean install -P ballerina'
    mavenVersionOption: 'Path'
    mavenDirectory: '$(build.sourcesdirectory)/maven/apache-maven-3.5.4'
    mavenSetM2Home: true

You can find the yaml file that works for all OSes here . 您可以在此处找到适用于所有操作系统的yaml文件。

Thanks @starian chen-MSFT for the heads up. 感谢@starian chen-MSFT的领导。

Refer to these steps: 请参考以下步骤:

  1. Download maven installer package and add to source control (You can download it during build/release too) 下载maven安装程序包并添加到源代码控制(您也可以在构建/发布期间下载它)
  2. Add Extract files task (Archive file patterns: apache-maven-3.5.4-bin.zip ; Destination folder: $(build.sourcesdirectory)\\maven ) 添加提取文件任务(存档文件模式: apache-maven-3.5.4-bin.zip ;目标文件夹: $(build.sourcesdirectory)\\maven
  3. Add PowerShell task: 添加PowerShell任务:

code: 码:

Write-Host "##vso[task.setvariable variable=M2_HOME;]$(build.sourcesdirectory)\maven\apache-maven-3.5.4"
Write-Host "##vso[task.setvariable variable=MAVEN_HOME;]$(build.sourcesdirectory)\maven\apache-maven-3.5.4"
Write-Host "##vso[task.prependpath]$(build.sourcesdirectory)\maven\apache-maven-3.5.4\bin"
  1. Add PowerShell task to check version: mvn --version 添加PowerShell任务以检查版本: mvn --version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 azure tfs 在 CI/CD 管道中配置应用程序设置 - How to configure app settings in CI/CD pipelines using azure tfs 使用 Azure DevOps CI/CD 管道自动部署 ADF 管道 - Automated Deployment of ADF Pipelines using Azure DevOps CI/CD Pipelines 如何在 Azure CI/CD 中使用 Azure CLI 步骤中的变量 - How to use variables in Azure CLI step in Azure CI/CD 使用或不使用触发器为 Azure 数据工厂创建 CI 和 CD 管道 - Creating CI and CD pipelines for Azure data factory with or without triggers 如何将AzureDevOps中的Azure KeyVault机密用作CI / CD定义中的变量? - How to use Azure KeyVault Secrets in AzureDevOps as varibles in CI/CD Definitions? 非 Azure SQL 版本是否支持 CI/CD SQL 管道? - Whether CI/CD SQL Pipeline is supported for NON Azure SQL Versions? Azure DevOps CI/CD 管道 Azure SQL 始终加密的数据库问题 - Azure DevOps CI/CD Pipelines for the Azure SQL Always Encrypted database Issues 如何在 Azure DevOps CI/CD 管道中使用 Azure SQL 始终加密 - How to use Azure SQL Always Encrypted in Azure DevOps CI/CD pipeline 如何使用 Azure DevOps CI/CD 部署多个 Azure 函数 - How can I use Azure DevOps CI/CD to deploy multiple Azure Functions Azure 中管道上的 CI 触发器 - CI Triggers on Pipelines in Azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM