microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.46k stars 2.6k forks source link

Bug/new feature - MavenV3 task's JaCoCo built-in code coverage tool can't support multi-module maven project. #16200

Closed QiuyongWang closed 2 years ago

QiuyongWang commented 2 years ago

Required Information

Question, Bug, or Feature?
Type: Bug or new Feature Enter Task Name: MavenV3
CodeCoverage Tool : JaCoCo.

Multi-module maven project can’t use this MavenV3 task’s built-in JaCoCo plugin code coverage tool to create report successfully. It is caused by the generic error – “Can't add different class with same name.”

For one example questionable class which is used among multiple modules: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Error while creating report [ERROR] around Ant part ...... @ 8:11 in /home/vsts/work/1/s/target/antrun/build-main.xml: Error while analyzing .m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar@org/apache/commons/collections/ArrayStack.class. Can't add different class with same name: org/apache/commons/collections/ArrayStack

This above error can be mitigated by adding this class org.apache.commons.collections.ArrayStack.class to the exclude filter in this MavenV3 task’s codeCoverageClassFilter with the value “-:org.apache.commons.collections.ArrayStack*”.

However, this codeCoverageClassFilter exclude filter doesn’t work for other questionable class, like the other error: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Error while creating report 2022-04-27T11:38:42.6046411Z [ERROR] around Ant part ...... @ 8:11 in /home/vsts/work/1/s/target/antrun/build-main.xml: Error while analyzing .m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar@antlr/ActionElement.class. Can't add different class with same name: antlr/ActionElement

Furthermore, it doesn’t make sense to explicit these classes which are only used in previous Maven project module by JaCoCo, so in next module which also uses this same class will be not allowed for JaCoCo plugin.

For the JaCoCo plugin itself does have the capability to support multi-module Maven project. List one article for EG to refer to : https://cylab.be/blog/97/compute-code-coverage-for-a-multi-module-maven-project-with-jacoco .

This scenario seems to be both a bug and kind of a new feature request – to fully support multi-module Maven project to use JaCoCo in this ADO MavenV3 task.

Current workaround: End user has to not to use this MavenV3 task’s JaCoCo coverage feature, but to set in his Maven project pom file, to directly use the JaCoCo-plugin to create report. Then this report can be published to the pipeline by adding the ADO PublishCodeCoverageResults task behind the MavenV3 task. And this workaround can not support the css in the report html to render perfectly in ADO web portal: errorCSSformatADOWebPortalReport Only after downloading the report from pipeline run, and open it from local file system in default browser, the report css can only be rendered well: GoodCSSformatLocalFileReport

QiuyongWang commented 2 years ago

@KonstantinTyukalov , ask you requested, I've submitted this new issue with details. Appreciate EG team review and prioritize it.

KonstantinTyukalov commented 2 years ago

@QiuyongWang thank you for the information provided! We will take a look at this once we've dealt with the higher priority tickets

kirill-ivlev commented 2 years ago

@QiuyongWang I tried to reproduce your issue with a dummy project (you can find it here: https://github.com/kirill-ivlev/maven-multimodule-dummy-project ). Both modules depend on the same Apache common collection. My pipeline finished with success, and no issues were found. Could you please add any additional steps to reproduce or share pipeline yml details?

QiuyongWang commented 2 years ago

@kirill-ivlev The user "mhainke" is facing this issue when using devops mavenV3 task for his multi-module maven project, who has participated in another issue - https://github.com/microsoft/azure-pipelines-tasks/issues/15868. I've suggested him to discuss with you in this issue to find appropriate materials for you.

kirill-ivlev commented 2 years ago

@QiuyongWang This issue was discussed offline, the customer agreed that we could close this thread.

Quick summary: If you want to include code coverage & test results in ADO you have two ways to achieve that:

  1. Configure project dependency and coverage module (as described here: https://cylab.be/blog/97/compute-code-coverage-for-a-multi-module-maven-project-with-jacoco).
  2. Don't include any additional plugins in pom.xml and just set up codeCoverageToolOption: 'JaCoCo' in azure-pipeline.yml (see example: https://github.com/kirill-ivlev/maven-multimodule-dummy-project/blob/master/azure-pipelines.yml.

In the second case: Maven@3 tasks will automatically modify required pom files and generate these reports.

Please note, that in the second case you also need to specify which module you need to cover with code-coverage tool by setting such options as codeCoverageClassFilesDirectories and codeCoverageClassFilesDirectories

Also, please feel free to refer to the prepared example project: https://github.com/kirill-ivlev/maven-multimodule-dummy-project And official task documentation: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops

However, we will update docs to mark such fields as codeCoverageClassFilesDirectories and codeCoverageClassFilesDirectories as required for the multi-module project