Skip to content

[BUG]: maven task runs build twice when using jacoco for coverage #21190

@falc0r

Description

@falc0r

New issue checklist

Task name

Maven@4

Task version

4.249.6

Issue Description

When using the maven task with codeCoverageToolOption: 'jacoco', some maven lifecycle phases are run twice. The goals of the first run are dictated by the user using the goals input and then the second run uses the verify goal. With this setup, a reasonable goals setting would be test to limit the amount of duplicated work but even then the compile phase, among others, will run more than once.

This extra maven run may seem somewhat innocuous in small projects, but for projects with thousands of classes and hundreds of thousands of lines of code the extra compile phase can add quite a bit of time to the build. The impact of the extra build time creates a couple of problems. First, the risk of reaching the 60 minute build timeout increases significantly. Second, for larger projects that would be negatively affected by the extra build time, those projects are more likely to need Managed DevOps Pools since the default build agents are fairly small in terms of CPU and memory so that means we're paying for build minutes and the extra build time increases cost.

Looking at maventask.ts for the MavenV4 task, you can see the first maven run occurs in the execBuild function and the second run occurs in the publishCodeCoverage function. Pull request #13558 attempts to mitigate the impact of the second run by adding the -Dmaven.test.skip=true flag, making the test phase of the second run basically a noop but that doesn't help with the compile phase. As mentioned in the original issue that this was reported in, and that triggered the PR linked above, the better solution would be to add the verify phase to the original run and handle everything in one shot but that isn't what ended up happening.

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Ubuntu 24.04

Relevant log output

N/A

Full task logs with system.debug enabled

No response

Repro steps

trigger:
  - master
pool:
  vmImage: ubuntu-latest
steps:
  - task: Maven@4
    displayName: Run maven build
    inputs:
      mavenPomFile: 'pom.xml'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.17'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/@(surefire|failsafe)-reports/TEST-*.xml'
      codeCoverageToolOption: 'JaCoCo'
      codeCoverageClassFilesDirectories: 'target/classes'
      codeCoverageSourceDirectories: 'src/main/java'
      codeCoverageFailIfEmpty: true
      goals: 'test'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions