Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 389
Riyafa Abdul Hameed Avatar asked Sep 14 '18 08:09

Riyafa Abdul Hameed


People also ask

How do I deploy a Maven project in Azure?

You can deploy a Spring Boot app or containerized Spring Boot app or any Web app to Azure App Service Linux or Windows: Deploy a Spring Boot app to Azure App Service. Deploy a containerized Spring Boot app to Azure App Service. Deploy a containerized Spring Boot app to Azure App Service via Azure Container Registry.


2 Answers

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.

like image 124
Riyafa Abdul Hameed Avatar answered Oct 14 '22 11:10

Riyafa Abdul Hameed


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
like image 37
starian chen-MSFT Avatar answered Oct 14 '22 12:10

starian chen-MSFT