简体   繁体   中英

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. The default version for maven used in Azure pipelines CI/CD is 3.3.9. I can see that there is a way to install a different version of java using Java tool installer . I don't find such an option in their documentation for maven.

But for maven it is possible to specify the

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.

Any help on how to use a different version for my maven build in Azure pipelines CI/CD would be appreciated.

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:

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 .

Thanks @starian chen-MSFT for the heads up.

Refer to these steps:

  1. Download maven installer package and add to source control (You can download it during build/release too)
  2. Add Extract files task (Archive file patterns: apache-maven-3.5.4-bin.zip ; Destination folder: $(build.sourcesdirectory)\\maven )
  3. Add PowerShell task:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM