如何在 CI/CD 的 Azure Pipelines 中使用较新版本的 Maven 进行构建
How to use newer versions of Maven for builds in Azure Pipelines for CI/CD
我需要 Maven 版本 3.5.3 或更高版本来构建我在 github 上托管的项目。 Azure 管道 CI/CD 中使用的 maven 的默认版本是 3.3.9。
我可以看到有一种方法可以使用 Java tool installer. I don't find such an option in their documentation 为 maven 安装不同版本的 java。
但是对于 maven 可以指定
mavenVersionOption: 'Default' # Options: default, path
mavenDirectory: # Required when mavenVersionOption == Path
但是作为新手,我不明白如何在此处安装maven 和指定路径。
任何有关如何在 Azure 管道中为我的 Maven 构建使用不同版本的帮助 CI/CD 将不胜感激。
参考这些步骤:
- 下载 maven 安装程序包并添加到源代码管理(您也可以在 build/release 期间下载)
- 添加提取文件任务(存档文件模式:
apache-maven-3.5.4-bin.zip
;目标文件夹:$(build.sourcesdirectory)\maven
)
- 添加 PowerShell 任务:
代码:
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"
- 添加 PowerShell 任务以检查版本:
mvn --version
因为我在 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
您可以找到适用于所有操作系统的 yaml 文件here。
感谢@starian chen-MSFT 的提醒。
我需要 Maven 版本 3.5.3 或更高版本来构建我在 github 上托管的项目。 Azure 管道 CI/CD 中使用的 maven 的默认版本是 3.3.9。 我可以看到有一种方法可以使用 Java tool installer. I don't find such an option in their documentation 为 maven 安装不同版本的 java。
但是对于 maven 可以指定
mavenVersionOption: 'Default' # Options: default, path
mavenDirectory: # Required when mavenVersionOption == Path
但是作为新手,我不明白如何在此处安装maven 和指定路径。
任何有关如何在 Azure 管道中为我的 Maven 构建使用不同版本的帮助 CI/CD 将不胜感激。
参考这些步骤:
- 下载 maven 安装程序包并添加到源代码管理(您也可以在 build/release 期间下载)
- 添加提取文件任务(存档文件模式:
apache-maven-3.5.4-bin.zip
;目标文件夹:$(build.sourcesdirectory)\maven
) - 添加 PowerShell 任务:
代码:
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"
- 添加 PowerShell 任务以检查版本:
mvn --version
因为我在 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
您可以找到适用于所有操作系统的 yaml 文件here。
感谢@starian chen-MSFT 的提醒。