Home > Back-end >  Use settings file in azure dev-ops pipeline maven task to resolve dependencies
Use settings file in azure dev-ops pipeline maven task to resolve dependencies

Time:06-09

I need to run a maven task in a Azure dev-ops pipeline using a settings file (used to resolve some dependencies from an internal repository). I can get the file using the "DownloadSecureFile@1" task and then I can copy it to the default working directory. Inside a bash task I am able to build the project using

mvn -s settings.xml verify

However I need to run the maven goal using the "Maven@3" task (the test coverage and SonarQube analysis configuration is done with it). If I specify the settings parameter

          - task: Maven@3
            displayName: Build and run tests
            inputs:
              mavenPomFile: "pom.xml"
              # mavenOptions: "-s settings.xml -Xmx512m $(MAVEN_OPTS)"
              mavenOptions: "-Xmx512m $(MAVEN_OPTS) --settings settings.xml"
              javaHomeOption: "JDKVersion"
              jdkVersionOption: "1.11"
              jdkArchitectureOption: "x64"
              publishJUnitResults: false
              goals: "verify"
              sonarQubeRunAnalysis: true

(MAVEN_OPTS is just a variable defining the local repo with -Dmaven.repo.local) the task fails with this error:

error

Maven is installed, without the settings parameter it will fail because it couldn't resolve the dependencies. The same thing happens if I use "-s" instead of "--settings".

Using the "ArtifactoryMaven@2" task I am able to execute the goal, but it doesn't seem to have all the options of the "Maven@3" task, and I couldn't figure out how to get it to use a specific repo for caching the dependencies.

CodePudding user response:

From your task definition, you defined the -s settings.xml at mavenOptions field.

This is the root cause of this issue.

You need to define the settings.xml at Option field.

For example: options: '-s settings.xml'

      - task: Maven@3
        displayName: Build and run tests
        inputs:
          mavenPomFile: "pom.xml"
          options: '-s settings.xml'
          mavenOptions: "-Xmx512m $(MAVEN_OPTS)"
          javaHomeOption: "JDKVersion"
          jdkVersionOption: "1.11"
          jdkArchitectureOption: "x64"
          publishJUnitResults: false
          goals: "verify"
          sonarQubeRunAnalysis: true

Refer to the doc: Maven task

  • Related