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

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

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
    src/main/java/...
    src/test/java/...
    pom.xml
模块2
    src/main/java/...
    src/test/java/...
    pom.xml
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

mod1
    src/main/java/...
    src/test/java/...
    pom.xml
mod2
    src/main/java/...
    src/test/java/...
    pom.xml
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父级中添加以下配置:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.6</version>
    <configuration>
        <excludes>
            <exclude>com/acme/test/*</exclude>
        </excludes>
    </configuration>
    <executions>
        <!-- 为集成测试准备代理 -->
        <execution>
            <id>jacoco-initialize</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>jacoco-site</id>
            <phase>package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>
英文:

For excluded test add next configuration in pom parent

&lt;plugin&gt;
    &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
    &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;0.8.6&lt;/version&gt;
    &lt;configuration&gt;
        &lt;excludes&gt;
            &lt;exclude&gt;com/acme/test/*&lt;/exclude&gt;
        &lt;/excludes&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
        &lt;!-- prepare agent for measuring integration tests --&gt;
        &lt;execution&gt;
            &lt;id&gt;jacoco-initialize&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;prepare-agent&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
            &lt;id&gt;jacoco-site&lt;/id&gt;
            &lt;phase&gt;package&lt;/phase&gt;
            &lt;goals&gt;
                &lt;goal&gt;report&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&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:

确定