Answers: <p>I forgot to add a MAVEN_OPTS variable in mavenOptions:<br>
      <code>mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'</code></p>
  
  <p>My pipeline.yml stayed like this:  </p>
  
  <pre><code>trigger:
  - master
  
  pool:
    vmImage: 'ubuntu-latest'
  
  variables:
    MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
    MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
  
  
  steps:
  
  - task: Cache@2
    inputs:
      key: 'maven | "$(Agent.OS)" | **/pom.xml'
      restoreKeys: |
        maven | "$(Agent.OS)"
        maven
      path: $(MAVEN_CACHE_FOLDER)
    displayName: Cache Maven local repo
  
  - task: Maven@3
    inputs:
      mavenPomFile: 'pom.xml'
      mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.8'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      goals: 'clean package'
      codeCoverageToolOption: JaCoCo
      sonarQubeRunAnalysis: false
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Pipeline.Workspace)'
      publishLocation: 'pipeline'
  
  - script: mvn install -B -e
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-15T19:47:53.217Z
Answers: 2020-05-15T19:47:53.217Z
Answers: danilo
Answers: <p>I made it work like this:</p>
  <pre><code>variables:
    MAVEN_CACHE_FOLDER: $(HOME)/.m2/repository
    MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
  
  trigger:
  - master
  
  pool:
    vmImage: 'ubuntu-latest'
  
  steps:
    - task: Cache@2
      displayName: 'Cache Maven local repo'
      inputs:
        key: '&quot;funcs&quot; | maven | &quot;$(Agent.OS)&quot; | pom.xml'
        restoreKeys: |
        path: $(MAVEN_CACHE_FOLDER)
  
    - task: Maven@3
      displayName: 'Build and Test'
      inputs:
        mavenPomFile: 'pom.xml'
        mavenOptions: '-Xmx2048m'
        javaHomeOption: 'JDKVersion'
        jdkVersionOption: '1.11'
        jdkArchitectureOption: 'x64'
        publishJUnitResults: true
        testResultsFiles: '**/surefire-reports/TEST-*.xml'
        goals: '-B package'
  
    - task: PublishCodeCoverageResults@1
      displayName: 'Publish code coverage'
      inputs:
        codeCoverageTool: 'JaCoCo'
        summaryFileLocation: '$(System.DefaultWorkingDirectory)/target/site/jacoco/jacoco.xml'
        pathToSources: '$(System.DefaultWorkingDirectory)/src/main/java'
        additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/target/jacoco.exec'
  </code></pre>
  <p>It has:</p>
  <ul>
  <li>caching of the Maven repository</li>
  <li>Run maven with <code>-B</code> to avoid download texts in the output</li>
  <li>Use Java 11</li>
  <li>Publish test reports</li>
  <li>Publish Jacoco code coverage</li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2022-12-27T13:58:32.813Z
Answers: About the line "path: $(MAVEN_CACHE_FOLDER)", is the identation correct?
Answers: Paulo Pedroso
Answers: CC BY-SA 4.0
Answers: 2021-07-16T13:49:36.640Z
Answers: 2021-07-16T13:49:36.640Z
Answers: Wim Deblauwe
Body: <p>I want to avoid maven downloading all dependencies from a remote repository in all build  </p>
  
  <p>I configured a cache, but all executions still download all dependencies.  </p>
  
  <p><a href="https://i.sstatic.net/adP3E.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/adP3E.png" alt="enter image description here"></a></p>
  
  <p>azure-pipelines.yml  </p>
  
  <pre><code>trigger:
  - master
  
  pool:
    vmImage: 'ubuntu-latest'
  
  variables:
    MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
    MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
  
  steps:
  - task: Maven@3
    inputs:
      mavenPomFile: 'pom.xml'
      mavenOptions: '-Xmx3072m'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.8'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      goals: 'clean package'
      codeCoverageToolOption: JaCoCo
      sonarQubeRunAnalysis: false
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Pipeline.Workspace)'
      publishLocation: 'pipeline'
  - task: Cache@2
    inputs:
      key: 'maven | "$(Agent.OS)" | **/pom.xml'
      restoreKeys: |
        maven | "$(Agent.OS)"
        maven
      path: $(MAVEN_CACHE_FOLDER)
    displayName: Cache Maven local repo
  
  - script: mvn install -B -e
  </code></pre>
  
Tags: <azure-pipelines><maven><repository>
Title: Using cached dependencies for pipelines in Azure Devops
UserDisplayName: danilo
ThreadText: # Using cached dependencies for pipelines in Azure Devops
  
  (Asked by: username_0 on 2020-05-15)
  
  I want to avoid maven downloading all dependencies from a remote repository in all build
  
  I configured a cache, but all executions still download all dependencies.
  
  [![enter image description here](https://i.sstatic.net/adP3E.png)](https://i.sstatic.net/adP3E.png)
  
  azure-pipelines.yml
  
  ```
  trigger:
  - master
  
  pool:
    vmImage: 'ubuntu-latest'
  
  variables:
    MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
    MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
  
  steps:
  - task: Maven@3
    inputs:
      mavenPomFile: 'pom.xml'
      mavenOptions: '-Xmx3072m'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.8'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      goals: 'clean package'
      codeCoverageToolOption: JaCoCo
      sonarQubeRunAnalysis: false
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Pipeline.Workspace)'
      publishLocation: 'pipeline'
  - task: Cache@2
    inputs:
      key: 'maven | "$(Agent.OS)" | **/pom.xml'
      restoreKeys: |
        maven | "$(Agent.OS)"
        maven
      path: $(MAVEN_CACHE_FOLDER)
    displayName: Cache Maven local repo
  
  - script: mvn install -B -e
  
  ```
  
  **Tags:** azure-pipelines, maven, repository
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-05-15. Score: 1
  
  I forgot to add a MAVEN\_OPTS variable in mavenOptions:  
  `mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'`
  
  My pipeline.yml stayed like this:
  
  ```
  trigger:
  - master
  
  pool:
    vmImage: 'ubuntu-latest'
  
  variables:
    MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
    MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
  
  steps:
  
  - task: Cache@2
    inputs:
      key: 'maven | "$(Agent.OS)" | **/pom.xml'
      restoreKeys: |
        maven | "$(Agent.OS)"
        maven
      path: $(MAVEN_CACHE_FOLDER)
    displayName: Cache Maven local repo
  
  - task: Maven@3
    inputs:
      mavenPomFile: 'pom.xml'
      mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.8'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      goals: 'clean package'
      codeCoverageToolOption: JaCoCo
      sonarQubeRunAnalysis: false
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Pipeline.Workspace)'
      publishLocation: 'pipeline'
  
  - script: mvn install -B -e
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2021-07-16. Score: 1
  
  I made it work like this:
  
  ```
  variables:
    MAVEN_CACHE_FOLDER: $(HOME)/.m2/repository
    MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
  
  trigger:
  - master
  
  pool:
    vmImage: 'ubuntu-latest'
  
  steps:
    - task: Cache@2
      displayName: 'Cache Maven local repo'
      inputs:
        key: '"funcs" | maven | "$(Agent.OS)" | pom.xml'
        restoreKeys: |
        path: $(MAVEN_CACHE_FOLDER)
  
    - task: Maven@3
      displayName: 'Build and Test'
      inputs:
        mavenPomFile: 'pom.xml'
        mavenOptions: '-Xmx2048m'
        javaHomeOption: 'JDKVersion'
        jdkVersionOption: '1.11'
        jdkArchitectureOption: 'x64'
        publishJUnitResults: true
        testResultsFiles: '**/surefire-reports/TEST-*.xml'
        goals: '-B package'
  
    - task: PublishCodeCoverageResults@1
      displayName: 'Publish code coverage'
      inputs:
        codeCoverageTool: 'JaCoCo'
        summaryFileLocation: '$(System.DefaultWorkingDirectory)/target/site/jacoco/jacoco.xml'
        pathToSources: '$(System.DefaultWorkingDirectory)/src/main/java'
        additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/target/jacoco.exec'
  
  ```
  
  It has:
  
  * caching of the Maven repository
  * Run maven with `-B` to avoid download texts in the output
  * Use Java 11
  * Publish test reports
  * Publish Jacoco code coverage
  
  > **Comments:**
  > **username_2**: About the line "path: $(MAVEN_CACHE_FOLDER)", is the identation correct?  
  
  ---
  
  