从Azure构建管道中排除多模块Maven项目中的测试目录,以使JaCoCo不包含它们。

huangapple go评论113阅读模式
英文:

Exclude test directories in multi-module maven projecty from JaCoCo when using Azure build pipeline

问题

这应该很容易,所以请帮助指导我正确的方向。

我已经成功地使用Maven在Azure Pipeline中构建我的Java项目。我也成功地获得了JaCoCo覆盖率报告。

我有一个包含多个模块的Maven项目。下面是一个示例项目结构。我想要排除所有子目录/包中的src/test/java中的内容。

我的项目

  1. 模块1
  2. src/main/java/...
  3. src/test/java/...
  4. pom.xml
  5. 模块2
  6. src/main/java/...
  7. src/test/java/...
  8. pom.xml
  9. pom.xml

我本来期望可以设置codeCoverageClassFilter-:*.src.test.java*.*,但我的各种尝试都没有奏效。如何正确排除所有这些测试目录的语句是什么?

英文:

This feels like it should be easy, so please help point me in the correct direction.

I am successfully using maven to build my java project using a Azure Pipeline. I am also successfully getting JaCoCo coverage reports.

I have a maven project with multiple modules. Below is a sample project structure. I want to exclude everything in all the sub src/test/java directories/packages.

myproject

  1. mod1
  2. src/main/java/...
  3. src/test/java/...
  4. pom.xml
  5. mod2
  6. src/main/java/...
  7. src/test/java/...
  8. pom.xml
  9. pom.xml

I would have expected something like setting codeCoverageClassFilter to -:*.src.test.java*.*, but none of my variations have worked. What is the correct statement to exclude all these test directories?

答案1

得分: 1

为了排除测试,请在pom父级中添加以下配置:

  1. <plugin>
  2. <groupId>org.jacoco</groupId>
  3. <artifactId>jacoco-maven-plugin</artifactId>
  4. <version>0.8.6</version>
  5. <configuration>
  6. <excludes>
  7. <exclude>com/acme/test/*</exclude>
  8. </excludes>
  9. </configuration>
  10. <executions>
  11. <!-- 为集成测试准备代理 -->
  12. <execution>
  13. <id>jacoco-initialize</id>
  14. <goals>
  15. <goal>prepare-agent</goal>
  16. </goals>
  17. </execution>
  18. <execution>
  19. <id>jacoco-site</id>
  20. <phase>package</phase>
  21. <goals>
  22. <goal>report</goal>
  23. </goals>
  24. </execution>
  25. </executions>
  26. </plugin>
英文:

For excluded test add next configuration in pom parent

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
  3. &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;0.8.6&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;excludes&gt;
  7. &lt;exclude&gt;com/acme/test/*&lt;/exclude&gt;
  8. &lt;/excludes&gt;
  9. &lt;/configuration&gt;
  10. &lt;executions&gt;
  11. &lt;!-- prepare agent for measuring integration tests --&gt;
  12. &lt;execution&gt;
  13. &lt;id&gt;jacoco-initialize&lt;/id&gt;
  14. &lt;goals&gt;
  15. &lt;goal&gt;prepare-agent&lt;/goal&gt;
  16. &lt;/goals&gt;
  17. &lt;/execution&gt;
  18. &lt;execution&gt;
  19. &lt;id&gt;jacoco-site&lt;/id&gt;
  20. &lt;phase&gt;package&lt;/phase&gt;
  21. &lt;goals&gt;
  22. &lt;goal&gt;report&lt;/goal&gt;
  23. &lt;/goals&gt;
  24. &lt;/execution&gt;
  25. &lt;/executions&gt;
  26. &lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年8月9日 09:47:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63321758.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定